Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2021-09-22 11:38:49 +0000
committerAndrey Loskutov2021-09-23 09:06:54 +0000
commitfeb6cf9983219098bed9b29579472555a5d33123 (patch)
tree8e9b35a6fd7415d3f33ebf297120f7c3e2d1f909
parentb033f6838f39057587b58613c5737e13b37798c4 (diff)
downloadeclipse.jdt.core-feb6cf9983219098bed9b29579472555a5d33123.tar.gz
eclipse.jdt.core-feb6cf9983219098bed9b29579472555a5d33123.tar.xz
eclipse.jdt.core-feb6cf9983219098bed9b29579472555a5d33123.zip
Bug 576152 - Compilation error: "The target type of this expression mustI20210924-0200I20210923-1800
be a functional interface" Reduced fix for bug 573933 only to case where targetType is instanceof ParameterizedTypeBinding. The new test case from bug 576152 covers the case where it can be ArrayBinding. Change-Id: Iabb6d224b24890f8f9745a1055ad5393d5536f1c Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/185699 Tested-by: JDT Bot <jdt-bot@eclipse.org> Reviewed-by: Jay Arthanareeswaran <jarthana@in.ibm.com> Reviewed-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java36
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java3
2 files changed, 38 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java
index 190d7f27a0..bffc9f25c3 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java
@@ -7276,6 +7276,42 @@ public void testBug562324b() {
},
"it runs");
}
+public void testBug576152() {
+ runConformTest(
+ new String[] {
+ "Example.java",
+ "\n"
+ + "import java.util.function.Supplier;\n"
+ + "\n"
+ + "public class Example {\n"
+ + " Example() {\n"
+ + " inspect(this::singleMethod);\n"
+ + " inspect(this::overloadedMethod);\n"
+ + " }\n"
+ + " void inspect(Inspector... inspectors) { }\n"
+ + " void singleMethod(byte[] input, int offset, int len) { }\n"
+ + " void overloadedMethod() { }\n"
+ + " void overloadedMethod(byte[] input, int offset, int len) { }\n"
+ + "\n"
+ + " public static void main(String[] args) {\n"
+ + " String s1 = hoge1(String::new);\n"
+ + " String s2 = hoge2(String::new); // Error. See the attached file.\n"
+ + " }\n"
+ + " static <T> T hoge1(Supplier<T> sup) {\n"
+ + " return null;\n"
+ + " }\n"
+ + " static <T> T hoge2(Supplier<T>... sup) {\n"
+ + " return null;\n"
+ + " }\n"
+ + "}\n"
+ + "\n"
+ + "@FunctionalInterface\n"
+ + "interface Inspector {\n"
+ + " void update(byte[] input, int offset, int len);\n"
+ + "}"
+ }
+ );
+}
public static Class testClass() {
return LambdaExpressionsTest.class;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java
index c33488f435..1dee15bbd9 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java
@@ -1258,7 +1258,8 @@ public class ReferenceExpression extends FunctionalExpression implements IPolyEx
} else if (copy.resolvedType != null && copy.resolvedType.isValidBinding() && copy.binding != null && copy.binding.isValidBinding()) {
return true;
} else {
- return !isPertinentToApplicability(targetType, null); // not mentioned in JLS (see prior art in LE.internalIsCompatibleWith()
+ boolean notPertinentToApplicability = targetType instanceof ParameterizedTypeBinding && !isPertinentToApplicability(targetType, null); // not mentioned in JLS (see prior art in LE.internalIsCompatibleWith()
+ return notPertinentToApplicability;
}
}

Back to the top