Skip to content

Commit

Permalink
Fixes #3217: Lambdas: use erased type. (#3252)
Browse files Browse the repository at this point in the history
  • Loading branch information
smillst authored Apr 30, 2020
1 parent 33b3e18 commit e38f895
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
20 changes: 20 additions & 0 deletions checker/tests/nullness/java8/lambda/Issue3217.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.function.Function;
import org.checkerframework.checker.nullness.qual.Nullable;

public class Issue3217<ModelA, ModelB, Value> {
private final Function<Function<ModelA, @Nullable Value>, Function<ModelB, @Nullable Value>>
proxyFunction;

public Issue3217(
Function<Function<ModelA, @Nullable Value>, Function<ModelB, @Nullable Value>>
proxyFunction) {
this.proxyFunction = proxyFunction;
}
}

class SubClass<A, V> extends Issue3217<A, A, V> {
public SubClass() {
super(x -> x);
Function<Function<A, @Nullable V>, Function<A, @Nullable V>> p = y -> y;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.checkerframework.framework.util.AnnotatedTypes;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.TreeUtils;
import org.checkerframework.javacutil.TypesUtils;

/**
* Converts a field or methods tree into an AnnotatedTypeMirror.
Expand Down Expand Up @@ -100,9 +101,11 @@ private static AnnotatedTypeMirror inferLambdaParamAnnotations(
AnnotatedExecutableType functionType = f.getFunctionTypeFromTree(lambdaDecl);
AnnotatedTypeMirror funcTypeParam = functionType.getParameterTypes().get(index);
if (TreeUtils.isImplicitlyTypedLambda(declaredInTree)) {
if (f.types.isSubtype(funcTypeParam.actualType, lambdaParam.actualType)) {
// The Java types should be exactly the same, but because invocation type
// inference (#979) isn't implement, check first.
// The Java types should be exactly the same, but because invocation type
// inference (#979) isn't implement, check first. Use the erased types because the
// type arguments are not substituted when the annotated type arguments are.
if (TypesUtils.isErasedSubtype(
funcTypeParam.actualType, lambdaParam.actualType, f.types)) {
return AnnotatedTypes.asSuper(f, funcTypeParam, lambdaParam);
}
lambdaParam.addMissingAnnotations(funcTypeParam.getAnnotations());
Expand Down

0 comments on commit e38f895

Please sign in to comment.