Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2013-05-01 21:47:49 +0000
committerStephan Herrmann2013-05-01 21:51:29 +0000
commit3e63bc390a0b11312443904f0f4ab28b84063258 (patch)
tree96f631802e1d27d0bfe0aaf694ded76129324a76
parent59cd3ccc4026ea304c459ffba8ea6eef6960ce4a (diff)
downloadorg.eclipse.objectteams-3e63bc390a0b11312443904f0f4ab28b84063258.tar.gz
org.eclipse.objectteams-3e63bc390a0b11312443904f0f4ab28b84063258.tar.xz
org.eclipse.objectteams-3e63bc390a0b11312443904f0f4ab28b84063258.zip
update jdt.core to 0848b8a6a9afff16623dfc6b0821adb833326b41 (13-02-07)
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java5
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java487
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java84
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java6
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java14
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java20
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java64
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java8
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java18
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties3
10 files changed, 539 insertions, 170 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
index 61d547d97..3d13d3eac 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
@@ -570,11 +570,13 @@ public void _test011_problem_categories() {
expectedProblemAttributes.put("IncompatibleExceptionInInheritedMethodThrowsClause", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("IncompatibleExceptionInThrowsClause", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT));
+ expectedProblemAttributes.put("IncompatibleLambdaParameterType", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("IncompatibleReturnType", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("IncompatibleReturnTypeForNonInheritedInterfaceMethod", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT));
expectedProblemAttributes.put("IncompatibleTypesInConditionalOperator", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("IncompatibleTypesInEqualityOperator", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("IncompatibleTypesInForeach", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
+
expectedProblemAttributes.put("IncorrectArityForParameterizedConstructor", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("IncorrectArityForParameterizedMethod", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("IncorrectArityForParameterizedType", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
@@ -766,6 +768,7 @@ public void _test011_problem_categories() {
expectedProblemAttributes.put("NeedToEmulateMethodAccess", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE));
expectedProblemAttributes.put("NoAdditionalBoundAfterTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("NoFieldOnBaseType", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
+ expectedProblemAttributes.put("NoGenericLambda", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("NoImplicitStringConversionForCharArrayExpression", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
expectedProblemAttributes.put("NoMessageSendOnArrayType", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("NoMessageSendOnBaseType", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
@@ -1404,6 +1407,7 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("IncompatibleTypesInConditionalOperator", SKIP);
expectedProblemAttributes.put("IncompatibleTypesInEqualityOperator", SKIP);
expectedProblemAttributes.put("IncompatibleTypesInForeach", SKIP);
+ expectedProblemAttributes.put("IncompatibleLambdaParameterType", SKIP);
expectedProblemAttributes.put("IncorrectArityForParameterizedConstructor", SKIP);
expectedProblemAttributes.put("IncorrectArityForParameterizedMethod", SKIP);
expectedProblemAttributes.put("IncorrectArityForParameterizedType", SKIP);
@@ -1596,6 +1600,7 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("NeedToEmulateMethodAccess", new ProblemAttributes(JavaCore.COMPILER_PB_SYNTHETIC_ACCESS_EMULATION));
expectedProblemAttributes.put("NoAdditionalBoundAfterTypeVariable", SKIP);
expectedProblemAttributes.put("NoFieldOnBaseType", SKIP);
+ expectedProblemAttributes.put("NoGenericLambda", SKIP);
expectedProblemAttributes.put("NoImplicitStringConversionForCharArrayExpression", new ProblemAttributes(JavaCore.COMPILER_PB_CHAR_ARRAY_IN_STRING_CONCATENATION));
expectedProblemAttributes.put("NoMessageSendOnArrayType", SKIP);
expectedProblemAttributes.put("NoMessageSendOnBaseType", SKIP);
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java
index 0c77cd6d1..ada6fcadf 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java
@@ -17,6 +17,10 @@
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
+import java.util.Map;
+
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+
import junit.framework.Test;
public class NegativeLambdaExpressionsTest extends AbstractRegressionTest {
@@ -1230,6 +1234,489 @@ public void test036() {
"Duplicate local variable args\n" +
"----------\n");
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382702 - [1.8][compiler] Lambda expressions should be rejected in disallowed contexts
+public void test037() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "interface I {\r\n" +
+ " int foo1(String x);\r\n" +
+ "}\r\n" +
+ "public class X {\r\n" +
+ " public static void main(String[] args) {\r\n" +
+ " System.out.println(\"Lambda in illegal context: \" + (() -> \"Illegal Lambda\"));\r\n" +
+ " System.out.println(\"Method Reference in illegal context: \" + System::exit);\r\n" +
+ " System.out.println(\"Constructor Reference in illegal context: \" + String::new);\r\n" +
+ " I sam1 = (x) -> x.length(); // OK\r\n" +
+// " I sam2 = ((String::length)); // OK\r\n" +
+// " I sam3 = (Math.random() > 0.5) ? String::length : String::hashCode; // OK\r\n" +
+// " I sam4 = (I)(String::length); // OK\r\n" +
+ " int x = (x) -> 10;\n" +
+ " X x2 = (x) -> 10;\n" +
+ " }\r\n" +
+ "}"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " System.out.println(\"Lambda in illegal context: \" + (() -> \"Illegal Lambda\"));\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The target type of this expression must be a functional interface\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " System.out.println(\"Method Reference in illegal context: \" + System::exit);\n" +
+ " ^^^^^^^^^^^^\n" +
+ "The target type of this expression must be a functional interface\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 8)\n" +
+ " System.out.println(\"Constructor Reference in illegal context: \" + String::new);\n" +
+ " ^^^^^^^^^^^^\n" +
+ "The target type of this expression must be a functional interface\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 10)\n" +
+ " int x = (x) -> 10;\n" +
+ " ^^^^^^^^^\n" +
+ "The target type of this expression must be a functional interface\n" +
+ "----------\n" +
+ "5. ERROR in X.java (at line 11)\n" +
+ " X x2 = (x) -> 10;\n" +
+ " ^^^^^^^^^\n" +
+ "The target type of this expression must be a functional interface\n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399537 - [1.8][compiler] Exceptions thrown from lambda body must match specification per function descriptor
+public void test038() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.io.EOFException;\n" +
+ "import java.io.IOException;\n" +
+ "interface I { void m() throws IOException; }\n" +
+ "interface J { void m() throws EOFException; }\n" +
+ "interface K { void m() throws ClassNotFoundException; }\n" +
+ "interface IJ extends I, J {}\n" +
+ "interface IJK extends I, J, K {}\n" +
+ "public class X {\n" +
+ " int var;\n" +
+ " IJ ij = () -> {\n" +
+ " if (var == 0) {\n" +
+ " throw new IOException();\n" +
+ " } else if (var == 2) {\n" +
+ " throw new EOFException();\n" +
+ " } else {\n" +
+ " throw new ClassNotFoundException(); \n" +
+ " }\n" +
+ " };\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 12)\n" +
+ " throw new IOException();\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Unhandled exception type IOException\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 16)\n" +
+ " throw new ClassNotFoundException(); \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Unhandled exception type ClassNotFoundException\n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399537 - [1.8][compiler] Exceptions thrown from lambda body must match specification per function descriptor
+public void test039() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.io.EOFException;\n" +
+ "import java.io.IOException;\n" +
+ "import java.sql.SQLException;\n" +
+ "import java.sql.SQLTransientException;\n" +
+ "import java.util.List;\n" +
+ "import java.util.concurrent.TimeoutException;\n" +
+ "interface A {\n" +
+ " List<String> foo(List<String> arg) throws IOException, SQLTransientException;\n" +
+ "}\n" +
+ "interface B {\n" +
+ " List foo(List<String> arg) throws EOFException, SQLException, TimeoutException;\n" +
+ "}\n" +
+ "interface C {\n" +
+ " List foo(List arg) throws Exception;\n" +
+ "}\n" +
+ "interface D extends A, B {}\n" +
+ "interface E extends A, B, C {}\n" +
+ "public class X {\n" +
+ " int var;\n" +
+ " D d = (x) -> {\n" +
+ " switch (var) {\n" +
+ " case 0 : throw new EOFException();\n" +
+ " case 1: throw new IOException();\n" +
+ " case 2: throw new SQLException();\n" +
+ " case 3: throw new SQLTransientException();\n" +
+ " case 4: throw new TimeoutException();\n" +
+ " default: throw new NullPointerException();\n" +
+ " }\n" +
+ " };\n" +
+ " E e = (x) -> {\n" +
+ " switch (var) {\n" +
+ " case 0 : throw new EOFException();\n" +
+ " case 1: throw new IOException();\n" +
+ " case 2: throw new SQLException();\n" +
+ " case 3: throw new SQLTransientException();\n" +
+ " case 4: throw new TimeoutException();\n" +
+ " default: throw new NullPointerException();\n" +
+ " }\n" +
+ " };\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. WARNING in X.java (at line 11)\n" +
+ " List foo(List<String> arg) throws EOFException, SQLException, TimeoutException;\n" +
+ " ^^^^\n" +
+ "List is a raw type. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "2. WARNING in X.java (at line 14)\n" +
+ " List foo(List arg) throws Exception;\n" +
+ " ^^^^\n" +
+ "List is a raw type. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "3. WARNING in X.java (at line 14)\n" +
+ " List foo(List arg) throws Exception;\n" +
+ " ^^^^\n" +
+ "List is a raw type. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 23)\n" +
+ " case 1: throw new IOException();\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Unhandled exception type IOException\n" +
+ "----------\n" +
+ "5. ERROR in X.java (at line 24)\n" +
+ " case 2: throw new SQLException();\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Unhandled exception type SQLException\n" +
+ "----------\n" +
+ "6. ERROR in X.java (at line 26)\n" +
+ " case 4: throw new TimeoutException();\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Unhandled exception type TimeoutException\n" +
+ "----------\n" +
+ "7. ERROR in X.java (at line 33)\n" +
+ " case 1: throw new IOException();\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Unhandled exception type IOException\n" +
+ "----------\n" +
+ "8. ERROR in X.java (at line 34)\n" +
+ " case 2: throw new SQLException();\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Unhandled exception type SQLException\n" +
+ "----------\n" +
+ "9. ERROR in X.java (at line 36)\n" +
+ " case 4: throw new TimeoutException();\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Unhandled exception type TimeoutException\n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399537 - [1.8][compiler] Exceptions thrown from lambda body must match specification per function descriptor
+public void test040() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " <P extends Exception> Object m() throws P;\n" +
+ "}\n" +
+ "interface J {\n" +
+ " <Q extends Exception> String m() throws Exception;\n" +
+ "}\n" +
+ "interface G extends I, J {}\n" +
+ "public class X {\n" +
+ " int var;\n" +
+ " G g1 = () -> {\n" +
+ " throw new Exception(); \n" +
+ " };\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " G g1 = () -> {\n" +
+ " throw new Exception(); \n" +
+ " };\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Illegal lambda expression: Method m of type J is generic \n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399537 - [1.8][compiler] Exceptions thrown from lambda body must match specification per function descriptor
+public void test041() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.io.IOException;\n" +
+ "import java.sql.SQLException;\n" +
+ "interface G1 {\n" +
+ " <E extends Exception> Object m(E p) throws E;\n" +
+ "}\n" +
+ "interface G2 {\n" +
+ " <F extends Exception> String m(F q) throws Exception;\n" +
+ "}\n" +
+ "interface G extends G1, G2 {} // G has descriptor <F extends Exception> ()->String throws F\n" +
+ "public class X {\n" +
+ " G g = (x) -> { // Elided type is inferred from descriptor to be F\n" +
+ " throw x; // ~== throw new F()\n" +
+ " };\n" +
+ "}\n" +
+ "class Y implements G {\n" +
+ " public <T extends Exception> String m(T t) throws T {\n" +
+ " throw t;\n" +
+ " }\n" +
+ " void foo(G1 g1) {\n" +
+ " g1.m(new IOException());\n" +
+ " }\n" +
+ " void foo(G2 g2) {\n" +
+ " g2.m(new SQLException());\n" +
+ " }\n" +
+ "}\n"
+
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 11)\n" +
+ " G g = (x) -> { // Elided type is inferred from descriptor to be F\n" +
+ " throw x; // ~== throw new F()\n" +
+ " };\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Illegal lambda expression: Method m of type G2 is generic \n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 20)\n" +
+ " g1.m(new IOException());\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Unhandled exception type IOException\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 23)\n" +
+ " g2.m(new SQLException());\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Unhandled exception type Exception\n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399537 - [1.8][compiler] Exceptions thrown from lambda body must match specification per function descriptor
+public void test042() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.io.IOException;\n" +
+ "import java.sql.SQLException;\n" +
+ "interface G1 {\n" +
+ " <E extends Exception> Object m(E p) throws E;\n" +
+ "}\n" +
+ "interface G2 {\n" +
+ " <F extends Exception> String m(F q) throws Exception;\n" +
+ "}\n" +
+ "interface G extends G1, G2 {} // G has descriptor <F extends Exception> ()->String throws F\n" +
+ "public class X {\n" +
+ " G g1 = (F x) -> {\n" +
+ " throw x;\n" +
+ " };\n" +
+ " G g2 = (IOException x) -> {\n" +
+ " throw x;\n" +
+ " };\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 11)\n" +
+ " G g1 = (F x) -> {\n" +
+ " throw x;\n" +
+ " };\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Illegal lambda expression: Method m of type G2 is generic \n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 14)\n" +
+ " G g2 = (IOException x) -> {\n" +
+ " throw x;\n" +
+ " };\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Illegal lambda expression: Method m of type G2 is generic \n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399224 - [1.8][compiler][internal] Implement TypeBinding.getSingleAbstractMethod
+public void test043() {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR);
+ options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportTypeParameterHiding, CompilerOptions.IGNORE);
+
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.util.List;\n" +
+ "interface A { void foo(); }\n" + // yes
+ "interface B { boolean equals(Object obj); }\n" + // no
+ "interface C extends B { void foo(); }\n" + // yes
+ "interface D<T> { boolean equals(Object obj); void foo(); }\n" + // yes
+ "interface E { void foo(); Object clone(); }\n" + // no
+ "interface F { void foo(List<String> p); }\n" + // yes
+ "interface G { void foo(List<String> p); }\n" + // yes
+ "interface H extends F, G {}\n" + // yes
+ "interface I { List foo(List<String> p); }\n" + // yes
+ "interface J { List<String> foo(List arg); }\n" + // yes
+ "interface K extends I, J {}\n" + // yes
+ "interface L { void foo(List<Integer> p); }\n" + // yes
+ "interface M extends I, L {}\n" + // no
+ "interface N { void foo(List<String> p, Class q); }\n" + // yes
+ "interface O { void foo(List p, Class<?> q); }\n" + // yes
+ "interface P extends N, O {}\n" + // no
+ "interface Q { long foo(); }\n" + // yes
+ "interface R { int foo(); }\n" + // yes
+ "interface S extends Q, R {}\n" + // no
+ "interface T<P> { void foo(P p); }\n" + // yes
+ "interface U<P> { void foo(P p); }\n" + // yes
+ "interface V<P, Q> extends T<P>, U<Q> {}\n" + // no
+ "interface W<T, N extends Number> { void m(T arg); void m(N arg); }\n" + // no
+ "interface X extends W<String, Integer> {}\n" + // no
+ "interface Y extends W<Integer, Integer> {}\n" + // yes
+
+ "class Z {\n" +
+ " A a = () -> {};\n" +
+ " B b = () -> {};\n" +
+ " C c = () -> {};\n" +
+ " D<?> d = () -> {};\n" +
+ " E e = () -> {};\n" +
+ " F f = (p0) -> {};\n" +
+ " G g = (p0) -> {};\n" +
+ " H h = (p0) -> {};\n" +
+ " I i = (p0) -> { return null; };\n" +
+ " J j = (p0) -> { return null; };\n" +
+ " K k = (p0) -> { return null; };\n" +
+ " L l = (p0) -> {};\n" +
+ " M m = (p0) -> {};\n" +
+ " N n = (p0, q0) -> {};\n" +
+ " O o = (p0, q0) -> {};\n" +
+ " P p = (p0, q0) -> {};\n" +
+ " Q q = () -> { return 0;};\n" +
+ " R r = () -> { return 0;};\n" +
+ " S s = () -> {};\n" +
+ " T<?> t = (p0) -> {};\n" +
+ " U<?> u = (p0) -> {};\n" +
+ " V<?,?> v = (p0) -> {};\n" +
+ " W<?,?> w = (p0) -> {};\n" +
+ " X x = (p0) -> {};\n" +
+ " Y y = (p0) -> {};\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 17)\n" +
+ " interface P extends N, O {}\n" +
+ " ^\n" +
+ "Name clash: The method foo(List, Class<?>) of type O has the same erasure as foo(List<String>, Class) of type N but does not override it\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 20)\n" +
+ " interface S extends Q, R {}\n" +
+ " ^\n" +
+ "The return types are incompatible for the inherited methods Q.foo(), R.foo()\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 23)\n" +
+ " interface V<P, Q> extends T<P>, U<Q> {}\n" +
+ " ^\n" +
+ "Name clash: The method foo(P) of type U<P> has the same erasure as foo(P) of type T<P> but does not override it\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 29)\n" +
+ " B b = () -> {};\n" +
+ " ^^^^^^^^\n" +
+ "The target type of this expression must be a functional interface\n" +
+ "----------\n" +
+ "5. ERROR in X.java (at line 32)\n" +
+ " E e = () -> {};\n" +
+ " ^^^^^^^^\n" +
+ "The target type of this expression must be a functional interface\n" +
+ "----------\n" +
+ "6. ERROR in X.java (at line 40)\n" +
+ " M m = (p0) -> {};\n" +
+ " ^^^^^^^^^^\n" +
+ "The target type of this expression must be a functional interface\n" +
+ "----------\n" +
+ "7. ERROR in X.java (at line 43)\n" +
+ " P p = (p0, q0) -> {};\n" +
+ " ^^^^^^^^^^^^^^\n" +
+ "The target type of this expression must be a functional interface\n" +
+ "----------\n" +
+ "8. ERROR in X.java (at line 46)\n" +
+ " S s = () -> {};\n" +
+ " ^^^^^^^^\n" +
+ "The target type of this expression must be a functional interface\n" +
+ "----------\n" +
+ "9. ERROR in X.java (at line 49)\n" +
+ " V<?,?> v = (p0) -> {};\n" +
+ " ^^^^^^^^^^\n" +
+ "The target type of this expression must be a functional interface\n" +
+ "----------\n" +
+ "10. ERROR in X.java (at line 50)\n" +
+ " W<?,?> w = (p0) -> {};\n" +
+ " ^^^^^^^^^^\n" +
+ "The target type of this expression must be a functional interface\n" +
+ "----------\n" +
+ "11. ERROR in X.java (at line 51)\n" +
+ " X x = (p0) -> {};\n" +
+ " ^^^^^^^^^^\n" +
+ "The target type of this expression must be a functional interface\n" +
+ "----------\n",
+ null,
+ false,
+ options);
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399224 - [1.8][compiler][internal] Implement TypeBinding.getSingleAbstractMethod
+public void test044() {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR);
+ options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportTypeParameterHiding, CompilerOptions.IGNORE);
+
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.util.List;\n" +
+ "interface A { <T> T foo(List<T> p); }\n" +
+ "interface B { <S> S foo(List<S> p); }\n" +
+ "interface C { <T, S> S foo(List<T> p); }\n" +
+ "interface D extends A, B {}\n" +
+ "interface E extends A, C {}\n" +
+
+ "class Z {\n" +
+ " A a = (p) -> { return null;};\n" +
+ " B b = (p) -> { return null;};\n" +
+ " C c = (p) -> { return null;};\n" +
+ " D d = (p) -> { return null;};\n" +
+ " E e = (p) -> { return null;};\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " interface E extends A, C {}\n" +
+ " ^\n" +
+ "Name clash: The method foo(List<T>) of type C has the same erasure as foo(List<T>) of type A but does not override it\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 8)\n" +
+ " A a = (p) -> { return null;};\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Illegal lambda expression: Method foo of type A is generic \n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 9)\n" +
+ " B b = (p) -> { return null;};\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Illegal lambda expression: Method foo of type B is generic \n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 10)\n" +
+ " C c = (p) -> { return null;};\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Illegal lambda expression: Method foo of type C is generic \n" +
+ "----------\n" +
+ "5. ERROR in X.java (at line 11)\n" +
+ " D d = (p) -> { return null;};\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Illegal lambda expression: Method foo of type A is generic \n" +
+ "----------\n" +
+ "6. ERROR in X.java (at line 12)\n" +
+ " E e = (p) -> { return null;};\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "The target type of this expression must be a functional interface\n" +
+ "----------\n",
+ null,
+ false,
+ options);
+}
public static Class testClass() {
return NegativeLambdaExpressionsTest.class;
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java
index 05b8a390d..6f5e29216 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java
@@ -41,68 +41,6 @@ public static Class testClass() {
return NullAnnotationTest.class;
}
-
-protected void setUp() throws Exception {
- super.setUp();
- if (this.LIBS == null) {
- String[] defaultLibs = getDefaultClassPaths();
- int len = defaultLibs.length;
- this.LIBS = new String[len+1];
- System.arraycopy(defaultLibs, 0, this.LIBS, 0, len);
- File bundleFile = FileLocator.getBundleFile(Platform.getBundle("org.eclipse.jdt.annotation"));
- if (bundleFile.isDirectory())
- this.LIBS[len] = bundleFile.getPath()+"/bin";
- else
- this.LIBS[len] = bundleFile.getPath();
- }
-}
-// Conditionally augment problem detection settings
-static boolean setNullRelatedOptions = true;
-protected Map getCompilerOptions() {
- Map defaultOptions = super.getCompilerOptions();
- if (setNullRelatedOptions) {
- defaultOptions.put(JavaCore.COMPILER_PB_NULL_REFERENCE, JavaCore.ERROR);
- defaultOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR);
- defaultOptions.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.ERROR);
- defaultOptions.put(JavaCore.COMPILER_PB_INCLUDE_ASSERTS_IN_NULL_ANALYSIS, JavaCore.ENABLED);
-
- defaultOptions.put(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION, JavaCore.DISABLED);
-
- // enable null annotations:
- defaultOptions.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED);
- // leave other new options at these defaults:
-// defaultOptions.put(CompilerOptions.OPTION_ReportNullContractViolation, JavaCore.ERROR);
-// defaultOptions.put(CompilerOptions.OPTION_ReportPotentialNullContractViolation, JavaCore.ERROR);
-// defaultOptions.put(CompilerOptions.OPTION_ReportNullContractInsufficientInfo, CompilerOptions.WARNING);
-
-// defaultOptions.put(CompilerOptions.OPTION_NullableAnnotationName, "org.eclipse.jdt.annotation.Nullable");
-// defaultOptions.put(CompilerOptions.OPTION_NonNullAnnotationName, "org.eclipse.jdt.annotation.NonNull");
- }
- return defaultOptions;
-}
-void runNegativeTestWithLibs(String[] testFiles, String expectedErrorLog) {
- runNegativeTest(
- testFiles,
- expectedErrorLog,
- this.LIBS,
- false /*shouldFlush*/);
-}
-void runNegativeTestWithLibs(boolean shouldFlushOutputDirectory, String[] testFiles, Map customOptions, String expectedErrorLog) {
- runNegativeTest(
- shouldFlushOutputDirectory,
- testFiles,
- this.LIBS,
- customOptions,
- expectedErrorLog,
- // runtime options
- JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
-}
-void runNegativeTestWithLibs(String[] testFiles, Map customOptions, String expectedErrorLog) {
- runNegativeTestWithLibs(false /* flush output directory */, testFiles, customOptions, expectedErrorLog);
-}
-void runConformTestWithLibs(String[] testFiles, Map customOptions, String expectedCompilerLog) {
- runConformTestWithLibs(false /* flush output directory */, testFiles, customOptions, expectedCompilerLog);
-}
void runConformTestWithLibs(String[] testFiles, Map customOptions, String expectedCompilerLog, String expectedOutput) {
runConformTest(
false, /* flush output directory */
@@ -114,28 +52,6 @@ void runConformTestWithLibs(String[] testFiles, Map customOptions, String expect
"",/* expected error */
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
-void runConformTestWithLibs(boolean shouldFlushOutputDirectory, String[] testFiles, Map customOptions, String expectedCompilerLog) {
- runConformTest(
- shouldFlushOutputDirectory,
- testFiles,
- this.LIBS,
- customOptions,
- expectedCompilerLog,
- "",/* expected output */
- "",/* expected error */
- JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
-}
-void runConformTest(String[] testFiles, Map customOptions, String expectedOutputString) {
- runConformTest(
- testFiles,
- expectedOutputString,
- null /*classLibraries*/,
- true /*shouldFlushOutputDirectory*/,
- null /*vmArguments*/,
- customOptions,
- null /*customRequestor*/);
-
-}
// a nullable argument is dereferenced without a check
public void test_nullable_paramter_001() {
runNegativeTest(
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
index 62d765d92..558111004 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
@@ -1359,7 +1359,11 @@ void setSourceStart(int sourceStart);
int lambdaSignatureMismatched = Internal + TypeRelated + 656;
/** @since 3.9 */
int lambdaParameterTypeMismatched = Internal + TypeRelated + 657;
- /**
+ /** @since 3.9 */
+ int IncompatibleLambdaParameterType = Internal + TypeRelated + 658;
+ /** @since 3.9 */
+ int NoGenericLambda = Internal + TypeRelated + 659;
+ /**
* More problems in generics
*/
/** @since 3.4 */
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java
index 74434f0cd..3332e2537 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java
@@ -27,7 +27,7 @@ import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
public abstract class FunctionalExpression extends Expression {
TypeBinding expectedType;
- MethodBinding singleAbstractMethod;
+ MethodBinding descriptor;
public FunctionalExpression() {
super();
@@ -43,13 +43,13 @@ public abstract class FunctionalExpression extends Expression {
public TypeBinding resolveType(BlockScope blockScope) {
this.constant = Constant.NotAConstant;
- MethodBinding descriptor = this.expectedType == null ? null : this.expectedType.getSingleAbstractMethod(blockScope);
- if (descriptor == null) {
+ MethodBinding sam = this.expectedType == null ? null : this.expectedType.getSingleAbstractMethod(blockScope);
+ if (sam == null) {
blockScope.problemReporter().targetTypeIsNotAFunctionalInterface(this);
return null;
}
- if (!descriptor.isValidBinding()) {
- switch (descriptor.problemId()) {
+ if (!sam.isValidBinding()) {
+ switch (sam.problemId()) {
case ProblemReasons.NoSuchSingleAbstractMethod:
blockScope.problemReporter().targetTypeIsNotAFunctionalInterface(this);
break;
@@ -59,8 +59,8 @@ public abstract class FunctionalExpression extends Expression {
}
return null;
}
- this.singleAbstractMethod = descriptor;
- return this.resolvedType = descriptor.declaringClass;
+ this.descriptor = sam;
+ return this.resolvedType = this.expectedType; // if interface IJ extends I, J() & IJ's descriptor is I.foo, can't return I
}
public int nullStatus(FlowInfo flowInfo) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
index 3756f025f..8a62a386d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
@@ -65,23 +65,27 @@ public class LambdaExpression extends FunctionalExpression implements ProblemSev
super.resolveType(blockScope); // compute & capture interface function descriptor in singleAbstractMethod.
final boolean argumentsTypeElided = argumentsTypeElided();
- final boolean haveDescriptor = this.singleAbstractMethod != null;
+ final boolean haveDescriptor = this.descriptor != null;
+ if (haveDescriptor && this.descriptor.typeVariables != Binding.NO_TYPE_VARIABLES) {
+ blockScope.problemReporter().lambdaExpressionCannotImplementGenericMethod(this, this.descriptor);
+ return this.resolvedType = null;
+ }
if (!haveDescriptor && argumentsTypeElided)
return null; // FUBAR, bail out...
this.scope = new MethodScope(blockScope, this, blockScope.methodScope().isStatic);
this.binding = new MethodBinding(ClassFileConstants.AccPublic | ExtraCompilerModifiers.AccUnresolved,
- haveDescriptor ? this.singleAbstractMethod.selector : TypeConstants.ANONYMOUS_METHOD,
- haveDescriptor ? this.singleAbstractMethod.returnType : null,
+ haveDescriptor ? this.descriptor.selector : TypeConstants.ANONYMOUS_METHOD,
+ haveDescriptor ? this.descriptor.returnType : null,
Binding.NO_PARAMETERS, // for now.
- haveDescriptor ? this.singleAbstractMethod.thrownExceptions : Binding.NO_EXCEPTIONS,
+ haveDescriptor ? this.descriptor.thrownExceptions : Binding.NO_EXCEPTIONS,
blockScope.enclosingSourceType()); // declaring class, for now - this is needed for annotation holder and such.
this.binding.typeVariables = Binding.NO_TYPE_VARIABLES; // descriptor may have type variables, but they are useless in lambda and lambda cannot be generic.
if (haveDescriptor) {
- int descriptorParameterCount = this.singleAbstractMethod.parameters.length;
+ int descriptorParameterCount = this.descriptor.parameters.length;
int lambdaArgumentCount = this.arguments != null ? this.arguments.length : 0;
if (descriptorParameterCount != lambdaArgumentCount) {
this.scope.problemReporter().lambdaSignatureMismatched(this);
@@ -107,7 +111,7 @@ public class LambdaExpression extends FunctionalExpression implements ProblemSev
}
TypeBinding parameterType;
- final TypeBinding expectedParameterType = haveDescriptor && i < this.singleAbstractMethod.parameters.length ? this.singleAbstractMethod.parameters[i] : null;
+ final TypeBinding expectedParameterType = haveDescriptor && i < this.descriptor.parameters.length ? this.descriptor.parameters[i] : null;
parameterType = argumentsTypeElided ? expectedParameterType : argument.type.resolveType(this.scope, true /* check bounds*/);
if (parameterType == null) {
buggyArguments = true;
@@ -121,7 +125,7 @@ public class LambdaExpression extends FunctionalExpression implements ProblemSev
if ((parameterType.tagBits & TagBits.HasMissingType) != 0) {
this.binding.tagBits |= TagBits.HasMissingType;
}
- if (haveDescriptor && expectedParameterType != null && parameterType != expectedParameterType) {
+ if (haveDescriptor && expectedParameterType != null && parameterType.isValidBinding() && parameterType != expectedParameterType) {
this.scope.problemReporter().lambdaParameterTypeMismatched(argument, argument.type, expectedParameterType);
}
@@ -290,7 +294,7 @@ public class LambdaExpression extends FunctionalExpression implements ProblemSev
// SH}
public TypeBinding expectedResultType() {
- return this.singleAbstractMethod != null && this.singleAbstractMethod.isValidBinding() ? this.singleAbstractMethod.returnType : null;
+ return this.descriptor != null && this.descriptor.isValidBinding() ? this.descriptor.returnType : null;
}
public void traverse(ASTVisitor visitor, BlockScope blockScope) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java
index be2b5f8b3..a98002423 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java
@@ -749,70 +749,6 @@ void checkTypeVariableMethods(TypeParameter typeParameter) {
}
}
}
-
-MethodBinding computeSubstituteMethod(MethodBinding inheritedMethod, MethodBinding currentMethod) {
- if (inheritedMethod == null) return null;
-//{ObjectTeams: use source-level params in case of enhanced callin methods:
-/* orig:
- if (currentMethod.parameters.length != inheritedMethod.parameters.length) return null; // no match
- :giro */
- if (currentMethod.getSourceParamLength() != inheritedMethod.getSourceParamLength()) return null; // no match
-// SH}
-
- // due to hierarchy & compatibility checks, we need to ensure these 2 methods are resolved
- if (currentMethod.declaringClass instanceof BinaryTypeBinding)
- ((BinaryTypeBinding) currentMethod.declaringClass).resolveTypesFor(currentMethod);
- if (inheritedMethod.declaringClass instanceof BinaryTypeBinding)
- ((BinaryTypeBinding) inheritedMethod.declaringClass).resolveTypesFor(inheritedMethod);
-
- TypeVariableBinding[] inheritedTypeVariables = inheritedMethod.typeVariables;
- int inheritedLength = inheritedTypeVariables.length;
- if (inheritedLength == 0) return inheritedMethod; // no substitution needed
- TypeVariableBinding[] typeVariables = currentMethod.typeVariables;
- int length = typeVariables.length;
- if (length == 0)
- return inheritedMethod.asRawMethod(this.environment);
- if (length != inheritedLength)
- return inheritedMethod; // no match JLS 8.4.2
-
- // interface I { <T> void foo(T t); }
- // class X implements I { public <T extends I> void foo(T t) {} }
- // for the above case, we do not want to answer the substitute method since its not a match
- TypeBinding[] arguments = new TypeBinding[length];
- System.arraycopy(typeVariables, 0, arguments, 0, length);
- ParameterizedGenericMethodBinding substitute =
- this.environment.createParameterizedGenericMethod(inheritedMethod, arguments);
- for (int i = 0; i < inheritedLength; i++) {
- TypeVariableBinding inheritedTypeVariable = inheritedTypeVariables[i];
- TypeBinding argument = arguments[i];
- if (argument instanceof TypeVariableBinding) {
- TypeVariableBinding typeVariable = (TypeVariableBinding) argument;
- if (typeVariable.firstBound == inheritedTypeVariable.firstBound) {
- if (typeVariable.firstBound == null)
- continue; // both are null
- } else if (typeVariable.firstBound != null && inheritedTypeVariable.firstBound != null) {
- if (typeVariable.firstBound.isClass() != inheritedTypeVariable.firstBound.isClass())
- return inheritedMethod; // not a match
- }
- if (Scope.substitute(substitute, inheritedTypeVariable.superclass) != typeVariable.superclass)
- return inheritedMethod; // not a match
- int interfaceLength = inheritedTypeVariable.superInterfaces.length;
- ReferenceBinding[] interfaces = typeVariable.superInterfaces;
- if (interfaceLength != interfaces.length)
- return inheritedMethod; // not a match
- next : for (int j = 0; j < interfaceLength; j++) {
- TypeBinding superType = Scope.substitute(substitute, inheritedTypeVariable.superInterfaces[j]);
- for (int k = 0; k < interfaceLength; k++)
- if (superType == interfaces[k])
- continue next;
- return inheritedMethod; // not a match
- }
- } else if (inheritedTypeVariable.boundCheck(substitute, argument, this.type.scope) != TypeConstants.OK) {
- return inheritedMethod;
- }
- }
- return substitute;
-}
boolean detectInheritedNameClash(MethodBinding inherited, MethodBinding otherInherited) {
if (!inherited.areParameterErasuresEqual(otherInherited))
return false;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java
index 6170f27a1..e1c6442f2 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java
@@ -2143,7 +2143,13 @@ public MethodBinding getSingleAbstractMethod(Scope scope) {
otherMethod = methods[j];
if (otherMethod.typeVariables != Binding.NO_TYPE_VARIABLES)
genericMethodSeen = true;
- if (!MethodVerifier.isParameterSubsignature(method, otherMethod, environment) || !MethodVerifier.areReturnTypesCompatible(method, otherMethod, environment))
+
+ if (genericMethodSeen) { // adapt type parameters.
+ otherMethod = MethodVerifier.computeSubstituteMethod(otherMethod, method, environment);
+ if (otherMethod == null)
+ continue next;
+ }
+ if (!MethodVerifier.isSubstituteParameterSubsignature(method, otherMethod, environment) || !MethodVerifier.areReturnTypesCompatible(method, otherMethod, environment))
continue next;
}
// If we reach here, we found a method that is override equivalent with every other method and is also return type substitutable. Compute kosher exceptions now ...
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
index 10c321356..d355cdbe4 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
@@ -85,6 +85,7 @@ import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.ast.FakedTrackingVariable;
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
import org.eclipse.jdt.internal.compiler.ast.FieldReference;
+import org.eclipse.jdt.internal.compiler.ast.FunctionalExpression;
import org.eclipse.jdt.internal.compiler.ast.ImportReference;
import org.eclipse.jdt.internal.compiler.ast.Initializer;
import org.eclipse.jdt.internal.compiler.ast.InstanceOfExpression;
@@ -1507,7 +1508,7 @@ public void cannotUseSuperInJavaLangObject(ASTNode reference) {
reference.sourceStart,
reference.sourceEnd);
}
-public void targetTypeIsNotAFunctionalInterface(ASTNode target) {
+public void targetTypeIsNotAFunctionalInterface(FunctionalExpression target) {
this.handle(
IProblem.TargetTypeNotAFunctionalInterface,
NoArgument,
@@ -1515,7 +1516,7 @@ public void targetTypeIsNotAFunctionalInterface(ASTNode target) {
target.sourceStart,
target.sourceEnd);
}
-public void illFormedParameterizationOfFunctionalInterface(ASTNode target) {
+public void illFormedParameterizationOfFunctionalInterface(FunctionalExpression target) {
this.handle(
IProblem.illFormedParameterizationOfFunctionalInterface,
NoArgument,
@@ -1523,7 +1524,7 @@ public void illFormedParameterizationOfFunctionalInterface(ASTNode target) {
target.sourceStart,
target.sourceEnd);
}
-public void lambdaSignatureMismatched(ASTNode target) {
+public void lambdaSignatureMismatched(LambdaExpression target) {
this.handle(
IProblem.lambdaSignatureMismatched,
NoArgument,
@@ -1537,12 +1538,21 @@ public void lambdaParameterTypeMismatched(Argument argument, TypeReference type,
String expectedTypeFullName = new String(expectedParameterType.readableName());
String expectedTypeShortName = new String(expectedParameterType.shortReadableName());
this.handle(
- IProblem.lambdaParameterTypeMismatched,
+ expectedParameterType.isTypeVariable() ? IProblem.IncompatibleLambdaParameterType : IProblem.lambdaParameterTypeMismatched,
new String[] { name, expectedTypeFullName },
new String[] { name, expectedTypeShortName },
type.sourceStart,
type.sourceEnd);
}
+public void lambdaExpressionCannotImplementGenericMethod(LambdaExpression lambda, MethodBinding sam) {
+ final String selector = new String(sam.selector);
+ this.handle(
+ IProblem.NoGenericLambda,
+ new String[] { selector, new String(sam.declaringClass.readableName())},
+ new String[] { selector, new String(sam.declaringClass.shortReadableName())},
+ lambda.sourceStart,
+ lambda.sourceEnd);
+}
public void caseExpressionMustBeConstant(Expression expression) {
this.handle(
IProblem.NonConstantExpression,
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
index 6f38f9400..bb53d86ee 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
@@ -620,7 +620,8 @@
655 = The target type of this expression is not a well formed parameterized type due to bound(s) mismatch
656 = Lambda expression's signature does not match the signature of the functional interface method
657 = Lambda expression's parameter {0} is expected to be of type {1}
-
+658 = Incompatible type specified for lambda expression's parameter {0}
+659 = Illegal lambda expression: Method {0} of type {1} is generic
### MORE GENERICS
660 = Unused type arguments for the non generic constructor {0}({1}) of type {2}; it should not be parameterized with arguments <{3}>
661 = Unused type parameter {0}

Back to the top