Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorssankaran2014-01-14 08:22:17 +0000
committerssankaran2014-01-14 08:22:17 +0000
commitefd527bb42c9215375b4d1cf91326767eee94a32 (patch)
tree14ca5c36f8404fc1eb85c42c55a3a28ca64fe0e0
parenta17a9082800c426c4984b5ef76877aab1c8e09e6 (diff)
downloadeclipse.jdt.core-efd527bb42c9215375b4d1cf91326767eee94a32.tar.gz
eclipse.jdt.core-efd527bb42c9215375b4d1cf91326767eee94a32.tar.xz
eclipse.jdt.core-efd527bb42c9215375b4d1cf91326767eee94a32.zip
Fixed Bug 423803 - [1.8][compiler] No error shown for ambiguous
reference to the method
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java66
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java12
2 files changed, 77 insertions, 1 deletions
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 c678a68192..d2ee26ecc1 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
@@ -8097,6 +8097,72 @@ public void test425621() throws Exception {
"Explicit type arguments cannot be specified in raw constructor reference expression\n" +
"----------\n");
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=423803, [1.8][compiler] No error shown for ambiguous reference to the method
+public void test423803() throws Exception {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "class C2 implements C2_Sup {\n" +
+ " public static final FI fi = x -> x++;\n" +
+ " public static final FL fl = x -> x++;\n" +
+ " {\n" +
+ " bar(x -> x++); // [1]\n" +
+ " bar(fl); \n" +
+ " }\n" +
+ " void bar(FI fi) { }\n" +
+ "}\n" +
+ "interface C2_Sup { \n" +
+ " default void bar(FL fl) { }\n" +
+ "}\n" +
+ "@FunctionalInterface\n" +
+ "interface FI {\n" +
+ " int foo(int x);\n" +
+ "}\n" +
+ "@FunctionalInterface\n" +
+ "interface FL {\n" +
+ " long foo(long x);\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " bar(x -> x++); // [1]\n" +
+ " ^^^\n" +
+ "The method bar(FI) is ambiguous for the type C2\n" +
+ "----------\n" +
+ "2. WARNING in X.java (at line 8)\n" +
+ " void bar(FI fi) { }\n" +
+ " ^^\n" +
+ "The parameter fi is hiding a field from type C2\n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=423803, [1.8][compiler] No error shown for ambiguous reference to the method
+public void test423803b() throws Exception {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X implements K {\n" +
+ " {\n" +
+ " bar(x -> x++); // [1]\n" +
+ " }\n" +
+ " void bar(I fi) { }\n" +
+ "}\n" +
+ "interface K { \n" +
+ " default void bar(J fl) { }\n" +
+ "}\n" +
+ "interface I {\n" +
+ " int foo(int x);\n" +
+ "}\n" +
+ "interface J {\n" +
+ " long foo(long x);\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " bar(x -> x++); // [1]\n" +
+ " ^^^\n" +
+ "The method bar(I) is ambiguous for the type X\n" +
+ "----------\n");
+}
public static Class testClass() {
return NegativeLambdaExpressionsTest.class;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java
index 6a4b6a4a61..119d47ad17 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java
@@ -1149,6 +1149,7 @@ public abstract class Scope {
MethodBinding concreteMatch) {
int startFoundSize = found.size;
+ final boolean sourceLevel18 = this.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8;
ReferenceBinding currentType = classHierarchyStart;
while (currentType != null) {
findMethodInSuperInterfaces(currentType, selector, found, invocationSite);
@@ -1160,6 +1161,7 @@ public abstract class Scope {
int foundSize = found.size;
if (foundSize > startFoundSize) {
// argument type compatibility check
+ next:
for (int i = startFoundSize; i < foundSize; i++) {
MethodBinding methodBinding = (MethodBinding) found.elementAt(i);
MethodBinding compatibleMethod = computeCompatibleMethod(methodBinding, argumentTypes, invocationSite, APPLICABILITY);
@@ -1167,6 +1169,13 @@ public abstract class Scope {
if (compatibleMethod.isValidBinding()) {
if (concreteMatch != null && environment().methodVerifier().areMethodsCompatible(concreteMatch, compatibleMethod))
continue; // can skip this method since concreteMatch overrides it
+ if (sourceLevel18) {
+ for (int j = 0; j < startFoundSize; j++) {
+ MethodBinding concreteMethod = (MethodBinding) found.elementAt(j);
+ if (concreteMethod != null && environment().methodVerifier().areMethodsCompatible(concreteMethod, compatibleMethod))
+ continue next; // can skip this method since concreteMethod overrides it
+ }
+ }
if (candidatesCount == 0) {
candidates = new MethodBinding[foundSize - startFoundSize + 1];
if (concreteMatch != null)
@@ -1571,6 +1580,7 @@ public abstract class Scope {
long complianceLevel = compilerOptions().complianceLevel;
boolean isCompliant14 = complianceLevel >= ClassFileConstants.JDK1_4;
boolean isCompliant15 = complianceLevel >= ClassFileConstants.JDK1_5;
+ boolean soureLevel18 = compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8;
ReferenceBinding classHierarchyStart = currentType;
MethodVerifier verifier = environment().methodVerifier();
while (currentType != null) {
@@ -1632,7 +1642,7 @@ public abstract class Scope {
MethodBinding[] candidates = null;
int candidatesCount = 0;
MethodBinding problemMethod = null;
- boolean searchForDefaultAbstractMethod = isCompliant14 && ! receiverTypeIsInterface && (receiverType.isAbstract() || receiverType.isTypeVariable());
+ boolean searchForDefaultAbstractMethod = soureLevel18 || (isCompliant14 && ! receiverTypeIsInterface && (receiverType.isAbstract() || receiverType.isTypeVariable()));
if (foundSize > 0) {
// argument type compatibility check
for (int i = 0; i < foundSize; i++) {

Back to the top