### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java,v retrieving revision 1.351 diff -u -r1.351 Scope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 19 Mar 2009 14:20:29 -0000 1.351 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 25 Mar 2009 17:41:37 -0000 @@ -541,18 +541,13 @@ method = ParameterizedGenericMethodBinding.computeCompatibleMethod(method, arguments, this, invocationSite); if (method == null) return null; // incompatible if (!method.isValidBinding()) return method; // bound check issue is taking precedence - } else if (genericTypeArguments != null) { + } else if (genericTypeArguments != null && compilerOptions().complianceLevel < ClassFileConstants.JDK1_7) { if (method instanceof ParameterizedGenericMethodBinding) { - if (!((ParameterizedGenericMethodBinding) method).wasInferred) { + if (!((ParameterizedGenericMethodBinding) method).wasInferred) // attempt to invoke generic method of raw type with type hints foo() - if (compilerOptions().complianceLevel < ClassFileConstants.JDK1_7) { - return new ProblemMethodBinding(method, method.selector, genericTypeArguments, ProblemReasons.TypeArgumentsForRawGenericMethod); - } - } - } else { - if (compilerOptions().complianceLevel < ClassFileConstants.JDK1_7) { - return new ProblemMethodBinding(method, method.selector, genericTypeArguments, ProblemReasons.TypeParameterArityMismatch); - } + return new ProblemMethodBinding(method, method.selector, genericTypeArguments, ProblemReasons.TypeArgumentsForRawGenericMethod); + } else if (!method.isOverriding() || !isOverriddenMethodGeneric(method)) { + return new ProblemMethodBinding(method, method.selector, genericTypeArguments, ProblemReasons.TypeParameterArityMismatch); } } @@ -1289,6 +1284,13 @@ // no match was found if (candidatesCount == 0) { + if (problemMethod != null) { + switch (problemMethod.problemId()) { + case ProblemReasons.TypeArgumentsForRawGenericMethod : + case ProblemReasons.TypeParameterArityMismatch : + return problemMethod; + } + } // abstract classes may get a match in interfaces; for non abstract // classes, reduces secondary errors since missing interface method // error is already reported @@ -2975,6 +2977,22 @@ return false; } + private boolean isOverriddenMethodGeneric(MethodBinding method) { + MethodVerifier verifier = environment().methodVerifier(); + ReferenceBinding currentType = method.declaringClass.superclass(); + while (currentType != null) { + MethodBinding[] currentMethods = currentType.getMethods(method.selector); + for (int i = 0, l = currentMethods.length; i < l; i++) { + MethodBinding currentMethod = currentMethods[i]; + if (currentMethod != null && currentMethod.original().typeVariables != Binding.NO_TYPE_VARIABLES) + if (verifier.doesMethodOverride(method, currentMethod)) + return true; + } + currentType = currentType.superclass(); + } + return false; + } + public boolean isSubtypeOfRawType(TypeBinding paramType) { TypeBinding t = paramType.leafComponentType(); if (t.isBaseType()) return false; #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java,v retrieving revision 1.792 diff -u -r1.792 GenericTypeTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 13 Feb 2009 21:40:42 -0000 1.792 +++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 25 Mar 2009 17:41:39 -0000 @@ -40775,22 +40775,24 @@ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=207935 // this case is not solved as expected in 1.5 and 1.6 mode; keeping the 1.7 mode -// activated +// activated test in all modes so we can track any changes public void test1203b() { - if (this.complianceLevel < ClassFileConstants.JDK1_7) { - return; - } String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_7 - ? "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " return this.foobar(one, two);\n" + - " ^^^^^^\n" + - "Unused type arguments for the non generic method foobar(String, String) of type X; it should not be parameterized with arguments \n" + - "----------\n" + - "2. ERROR in X.java (at line 16)\n" + - " this.foobar(one, two);\n" + - " ^^^^^^\n" + - "Incorrect number of type arguments for generic method foobar(String, String) of type Y; it cannot be parameterized with arguments \n" + + ? "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " return this.foobar(one, two);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method foobar(String, String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " return this.foobar2(one, two);// silenced\n" + + " ^^^^^^^\n" + + "The method foobar2(String, String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " this.foobar(one, two);\n" + + " ^^^^^^\n" + + "Incorrect number of type arguments for generic method foobar(String, String) of type Y; it cannot be parameterized with arguments \n" + "----------\n" : "----------\n" + "1. WARNING in X.java (at line 4)\n" + @@ -40829,6 +40831,169 @@ expectedOutput); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=207935 +public void test1203c() { + String[] sources = + new String[] { + "X.java", + "class X extends Y {\n" + + " public static void main(String[] args) {\n" + + " String s = \"\";\n" + + " new X(). a(s);\n" + // fails before 7 + " new X(). b(s, s);\n" + // fails before 7 + " new X(). c(s, s);\n" + // works in 1.5, 6.0 & 7.0 + " new X(). d(s, s);\n" + // works in 1.5, 6.0 & 7.0 + " }\n" + + " @Override void a(String one) {}\n" + + " void b(String one, Object two) {}\n" + + " @Override void c(String one, String two) {}\n" + + " @Override void d(String one, Object two) {}\n" + + "}\n" + + "class Y extends Z {\n" + + " void a(String one) {}\n" + + " void b(String one) {}\n" + + " @Override void c(String one, String two) {}\n" + + "}\n" + + "class Z {\n" + + " void c(String one, String two) {}\n" + + " void d(String one, U u) {}\n" + + "}" + }; + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + runNegativeTest( + sources, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new X(). a(s);\n" + + " ^\n" + + "The method a(String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " new X(). b(s, s);\n" + + " ^\n" + + "The method b(String, Object) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " new X(). c(s, s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method c(String, String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " new X(). d(s, s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method d(String, Object) of type X; it should not be parameterized with arguments \n" + + "----------\n"); + } else { + runConformTest( + true, + sources, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new X(). a(s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method a(String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " new X(). b(s, s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method b(String, Object) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " new X(). c(s, s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method c(String, String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " new X(). d(s, s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method d(String, Object) of type X; it should not be parameterized with arguments \n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=207935 +public void test1203d() { + String[] sources = + new String[] { + "X.java", + "class X implements I {\n" + + " public static void main(String[] args) {\n" + + " String s = \"\";\n" + + " new X(). a(s);\n" + // fails before 7 + " new X(). b(s, s);\n" + // fails before 7 + " new X(). c(s, s);\n" + // fails before 7 + " new X(). d(s, s);\n" + // fails before 7 + " }\n" + + " public void a(String one) {}\n" + + " public void b(String one, Object two) {}\n" + + " public void c(String one, String two) {}\n" + + " public void d(String one, Object two) {}\n" + + "}\n" + + "interface I extends J {\n" + + " void a(String one);\n" + + " void c(String one, String two);\n" + + "}\n" + + "interface J {\n" + + " void c(String one, String two);\n" + + " void d(String one, U u);\n" + + "}" + }; + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + runNegativeTest( + sources, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new X(). a(s);\n" + + " ^\n" + + "The method a(String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " new X(). b(s, s);\n" + + " ^\n" + + "The method b(String, Object) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " new X(). c(s, s);\n" + + " ^\n" + + "The method c(String, String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " new X(). d(s, s);\n" + + " ^\n" + + "The method d(String, Object) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); + } else { + runConformTest( + true, + sources, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new X(). a(s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method a(String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " new X(). b(s, s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method b(String, Object) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " new X(). c(s, s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method c(String, String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " new X(). d(s, s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method d(String, Object) of type X; it should not be parameterized with arguments \n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } +} + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=207299 public void test1204() { this.runConformTest(