Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore null in generic lambda tparams #446

Merged
merged 1 commit into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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