diff options
| author | ssankaran | 2014-02-13 05:05:49 +0000 |
|---|---|---|
| committer | ssankaran | 2014-02-13 05:05:49 +0000 |
| commit | c9c353b1f3633c7934ab02e6b5f4d6f7b6d921d9 (patch) | |
| tree | a432b72ac241b49b7753feec40815ef47759583e | |
| parent | 8b9431052e3d61392fc8179c11535d264307c499 (diff) | |
| download | eclipse.jdt.core-c9c353b1f3633c7934ab02e6b5f4d6f7b6d921d9.tar.gz eclipse.jdt.core-c9c353b1f3633c7934ab02e6b5f4d6f7b6d921d9.tar.xz eclipse.jdt.core-c9c353b1f3633c7934ab02e6b5f4d6f7b6d921d9.zip | |
Fixed Bug 427478 - [1.8][compiler] Wrong "Duplicate default methods"
error on AbstractDoubleSpliterator
2 files changed, 67 insertions, 6 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java index b963ee09ee..45a4fb49a7 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java @@ -2411,7 +2411,7 @@ public class InterfaceMethodsTest extends AbstractComparableTest { "B.foo"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427478, [1.8][compiler] Wrong "Duplicate default methods" error on AbstractDoubleSpliterator - public void _test427478() throws Exception { + public void test427478() throws Exception { // extracted smaller test case. this.runConformTest( new String[] { "X.java", @@ -2434,7 +2434,47 @@ public class InterfaceMethodsTest extends AbstractComparableTest { "abstract class AbstractDoubleSpliterator implements X.OfDouble {\n" + "}\n", }, - "A.foo\n" + - "B.foo"); - } + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427478, [1.8][compiler] Wrong "Duplicate default methods" error on AbstractDoubleSpliterator + public void test427478a() throws Exception { // full test case. + this.runConformTest( + new String[] { + "Spliterator.java", + "import java.util.function.Consumer;\n" + + "import java.util.function.DoubleConsumer;\n" + + "public interface Spliterator<T> {\n" + + " default void forEachRemaining(Consumer<? super T> action) {\n" + + " }\n" + + " public interface OfPrimitive<T, T_CONS, T_SPLITR extends OfPrimitive<T, T_CONS, T_SPLITR>>\n" + + " extends Spliterator<T> {\n" + + " // overloads Spliterator#forEachRemaining(Consumer<? super T>)\n" + + " default void forEachRemaining(T_CONS action) {\n" + + " }\n" + + " }\n" + + " public interface OfDouble extends OfPrimitive<Double, DoubleConsumer, OfDouble> {\n" + + " @Override // the method from Spliterator\n" + + " default void forEachRemaining(Consumer<? super Double> action) {\n" + + " }\n" + + " \n" + + " @Override // the method from OfPrimitive\n" + + " default void forEachRemaining(DoubleConsumer action) {\n" + + " }\n" + + " }\n" + + "}\n" + + "class Spliterators {\n" + + " /* Error on class: Duplicate default methods named forEachRemaining with\n" + + " * the parameters (Consumer<? super Double>) and (Consumer<? super T>) are\n" + + " * inherited from the types Spliterator.OfDouble and Spliterator<Double>\n" + + " */\n" + + " public abstract static class AbstractDoubleSpliterator implements Spliterator.OfDouble {\n" + + " /* Implementation that prevents the compile error: */\n" + + "// @Override // the method from Spliterator\n" + + "// public void forEachRemaining(Consumer<? super Double> action) {\n" + + "// }\n" + + " }\n" + + "}\n", + }, + ""); + } } 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 08b4b2f38f..33f0afddae 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 @@ -651,8 +651,29 @@ void checkMethods() { } if (index == -1) continue; - if (index > 0) - checkInheritedMethods(matchingInherited, index + 1, isOverridden, isInherited); // pass in the length of matching + if (index > 0) { + int length = index + 1; + boolean[] matchingIsOverridden; + boolean[] matchingIsInherited; + if (length != inheritedLength) { // transfer inherited & overridden status to align with subset of methods. + matchingIsOverridden = new boolean[length]; + matchingIsInherited = new boolean[length]; + for (int j = 0; j < length; j++) { + for (int k = 0; k < inheritedLength; k++) { + if (matchingInherited[j] == inherited[k]) { + matchingIsOverridden[j] = isOverridden[k]; + matchingIsInherited[j] = isInherited[k]; + break; + } + } + } + } else { + matchingIsOverridden = isOverridden; + matchingIsInherited = isInherited; + } + + checkInheritedMethods(matchingInherited, length, matchingIsOverridden, matchingIsInherited); // pass in the length of matching + } else if (mustImplementAbstractMethods && matchingInherited[0].isAbstract() && matchMethod == null) checkAbstractMethod(matchingInherited[0]); while (index >= 0) matchingInherited[index--] = null; // clear the previous contents of the matching methods |
