Skip to content

Commit

Permalink
Merge pull request #446 from eed3si9n/wip/389
Browse files Browse the repository at this point in the history
Ignore null in generic lambda tparams
  • Loading branch information
eed3si9n committed Oct 26, 2017
2 parents ee74feb + 573c4bd commit 73d0585
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,14 @@ object ClassToAPI {
accumulate(t).filterNot(_ == null).distinct
}

@deprecated("No longer used", "0.13.0")
def parents(c: Class[_]): Seq[api.Type] = types(allSuperTypes(c))
def types(ts: Seq[Type]): Array[api.Type] = (ts filter (_ ne null) map reference).toArray
def types(ts: Seq[Type]): Array[api.Type] =
ts.filter(_ ne null).map(reference).toArray
def upperBounds(ts: Array[Type]): api.Type =
api.Structure.of(lzy(types(ts)), lzyEmptyDefArray, lzyEmptyDefArray)

@deprecated("No longer used", "0.13.0")
def parents(c: Class[_]): Seq[api.Type] = types(allSuperTypes(c))

@deprecated("Use fieldToDef[4] instead", "0.13.9")
def fieldToDef(enclPkg: Option[String])(f: Field): api.FieldLike = {
val c = f.getDeclaringClass
Expand Down Expand Up @@ -496,12 +498,18 @@ object ClassToAPI {
api.Projection.of(api.Singleton.of(pathFromString(p)), cls)
}
}

// sbt/zinc#389: Ignore nulls coming from generic parameter types of lambdas
private[this] def ignoreNulls[T](genericTypes: Array[T]): Array[T] =
genericTypes.filter(_ != null)

def referenceP(t: ParameterizedType): api.Parameterized = {
val targs = t.getActualTypeArguments
val targs = ignoreNulls(t.getActualTypeArguments)
val args = if (targs.isEmpty) emptyTypeArray else arrayMap(targs)(t => reference(t): api.Type)
val base = reference(t.getRawType)
api.Parameterized.of(base, args)
}

def reference(t: Type): api.Type =
t match {
case _: WildcardType => reference("_")
Expand Down Expand Up @@ -557,7 +565,7 @@ object ClassToAPI {
case _: GenericSignatureFormatError => f.getType
}
private[this] def parameterTypes(c: Constructor[_]): Array[Type] =
try c.getGenericParameterTypes
try ignoreNulls(c.getGenericParameterTypes)
catch {
case _: GenericSignatureFormatError => convert(c.getParameterTypes)
}
Expand All @@ -567,7 +575,7 @@ object ClassToAPI {
case _: GenericSignatureFormatError => convert(c.getExceptionTypes)
}
private[this] def parameterTypes(m: Method): Array[Type] =
try m.getGenericParameterTypes
try ignoreNulls(m.getGenericParameterTypes)
catch {
case _: GenericSignatureFormatError => convert(m.getParameterTypes)
}
Expand All @@ -581,7 +589,6 @@ object ClassToAPI {
catch {
case _: GenericSignatureFormatError => convert(m.getExceptionTypes)
}

private[this] def typeParameterTypes[T](m: Constructor[T]): Array[TypeVariable[Constructor[T]]] =
try m.getTypeParameters
catch {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package typeparameters;

import java.util.function.Supplier;

public class Example {

static <I, O> void call() {
Supplier<BaseBlah<I, O>> blah = () ->
new BaseBlah<I, O>() {
@Override
protected O getResponseInternal(I i) {
return null;
}
};
}

public static void main(String[] args) {
Example.<String, String>call();
}
}

abstract class BaseBlah<I, O> {
protected O getResponseInternal(I i) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> compile

0 comments on commit 73d0585

Please sign in to comment.