Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 218319 Details for
Bug 383780
[compiler] Eclipse 4.2 creates ambiguous varargs method error in 1.6 compliance mode (does not mimic JDK bug)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
proposed fix v2.1 + regression tests
Fixed-bug-383780-Eclipse-42-fails-to-compile-valid-J_2.patch (text/plain), 15.04 KB, created by
Ayushman Jain
on 2012-07-05 04:11:58 EDT
(
hide
)
Description:
proposed fix v2.1 + regression tests
Filename:
MIME Type:
Creator:
Ayushman Jain
Created:
2012-07-05 04:11:58 EDT
Size:
15.04 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java >index 536723b..70dd308 100644 >--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java >+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2011 IBM Corporation and others. >+ * Copyright (c) 2005, 2012 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -33,7 +33,7 @@ > // Static initializer to specify tests subset using TESTS_* static variables > // All specified tests which does not belong to the class are skipped... > static { >-// TESTS_NAMES = new String[] { "test000" }; >+// TESTS_NAMES = new String[] { "test033" }; > // TESTS_NUMBERS = new int[] { 61 }; > // TESTS_RANGE = new int[] { 11, -1 }; > } >@@ -798,6 +798,55 @@ > "----------\n" > ); > } >+ >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383780 >+ public void test015_tolerate() throws Exception { >+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; >+ Map options = getCompilerOptions(); >+ try { >+ System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "true"); >+ if (this.complianceLevel >= ClassFileConstants.JDK1_7) { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static void main(String[] s) {\n" + >+ " Y.count(new int[0]);\n" + // for some reason this is not ambiguous >+ " }\n" + >+ "}\n" + >+ "class Y {\n" + >+ " public static void count(int[] array, int ... values) { System.out.print(1); }\n" + >+ " public static void count(int[] array, int[] ... values) { System.out.print(2); }\n" + >+ "}\n", >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 3)\n" + >+ " Y.count(new int[0]);\n" + >+ " ^^^^^\n" + >+ "The method count(int[], int[]) is ambiguous for the type Y\n" + >+ "----------\n", >+ null, true, options); >+ } else { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static void main(String[] s) {\n" + >+ " Y.count(new int[0]);\n" + // for some reason this is not ambiguous >+ " }\n" + >+ "}\n" + >+ "class Y {\n" + >+ " public static void count(int[] array, int ... values) { System.out.print(1); }\n" + >+ " public static void count(int[] array, int[] ... values) { System.out.print(2); }\n" + >+ "}\n", >+ }, >+ "1", >+ null, true, null, options, null); >+ } >+ } finally { >+ System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "false"); >+ } >+ } > > public void test016() { // check behaviour of Scope.mostSpecificMethodBinding() > this.runNegativeTest( // but this call is ambiguous >@@ -1235,7 +1284,7 @@ > }, > "1"); > } >- //https://bugs.eclipse.org/bugs/show_bug.cgi?id=102631 >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=102631 > public void test033() { > this.runNegativeTest( > new String[] { >@@ -1301,6 +1350,61 @@ > "The method c(boolean, boolean, Object[]) is ambiguous for the type X\n" + > "----------\n" > ); >+ } >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383780 >+ public void test033_tolerate() { >+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; >+ Map options = getCompilerOptions(); >+ try { >+ System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "true"); >+ if (this.complianceLevel >= ClassFileConstants.JDK1_7) { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void a(boolean b, Object... o) {System.out.print(1);}\n" + >+ " void a(Object... o) {System.out.print(2);}\n" + >+ " public static void main(String[] args) {\n" + >+ " X x = new X();\n" + >+ " x.a(true);\n" + >+ " x.a(true, \"foobar\");\n" + >+ " x.a(\"foo\", \"bar\");\n" + >+ " }\n" + >+ "}\n", >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 6)\n" + >+ " x.a(true);\n" + >+ " ^\n" + >+ "The method a(boolean, Object[]) is ambiguous for the type X\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 7)\n" + >+ " x.a(true, \"foobar\");\n" + >+ " ^\n" + >+ "The method a(boolean, Object[]) is ambiguous for the type X\n" + >+ "----------\n", >+ null, true, options); >+ } else { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void a(boolean b, Object... o) {System.out.print(1);}\n" + >+ " void a(Object... o) {System.out.print(2);}\n" + >+ " public static void main(String[] args) {\n" + >+ " X x = new X();\n" + >+ " x.a(true);\n" + >+ " x.a(true, \"foobar\");\n" + >+ " x.a(\"foo\", \"bar\");\n" + >+ " }\n" + >+ "}\n", >+ }, >+ "112", >+ null, true, null, options, null); >+ } >+ } finally { >+ System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "false"); >+ } > } > //https://bugs.eclipse.org/bugs/show_bug.cgi?id=106106 > public void test034() { >@@ -2818,6 +2922,106 @@ > }, > "Done"); > } >+ >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383780 >+ public void test070_tolerate() throws Exception { >+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; >+ Map options = getCompilerOptions(); >+ try { >+ System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "true"); >+ if (this.complianceLevel < ClassFileConstants.JDK1_7) { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static void foo(int ...i) {}\n" + >+ " public static void foo(double...d) {}\n" + >+ " public static void main(String[] args) {\n" + >+ " foo(1, 2, 3);\n" + >+ " System.out.println (\"Done\");\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " foo(1, 2, 3);\n" + >+ " ^^^\n" + >+ "The method foo(int[]) is ambiguous for the type X\n" + >+ "----------\n", >+ null, true, options); >+ } else { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static void foo(int ...i) {}\n" + >+ " public static void foo(double...d) {}\n" + >+ " public static void main(String[] args) {\n" + >+ " foo(1, 2, 3);\n" + >+ " System.out.println (\"Done\");\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "Done", >+ null, true, null, options, null); >+ } >+ } finally { >+ System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "false"); >+ } >+ >+ } >+ >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383780 >+ public void test070_tolerate2() throws Exception { >+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; >+ Map options = getCompilerOptions(); >+ try { >+ System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "true"); >+ if (this.complianceLevel >= ClassFileConstants.JDK1_7) { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "import java.util.Arrays;\n" + >+ "public class X {\n" + >+ " public static void test(int... a) {\n" + >+ " System.out.println(Arrays.toString(a));\n}\n" + >+ " public static <T> void test(Object... a) {\n" + >+ " System.out.println(Arrays.toString(a));\n}\n" + >+ " public static void main(String[] args) {\n" + >+ " test(1);\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 10)\n" + >+ " test(1);\n" + >+ " ^^^^\n" + >+ "The method test(int[]) is ambiguous for the type X\n" + >+ "----------\n", >+ null, true, options); >+ } else { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "import java.util.Arrays;\n" + >+ "public class X {\n" + >+ " public static void test(int... a) {\n" + >+ " System.out.println(Arrays.toString(a));\n}\n" + >+ " public static <T> void test(Object... a) {\n" + >+ " System.out.println(Arrays.toString(a));\n}\n" + >+ " public static void main(String[] args) {\n" + >+ " test(1);\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "[1]", >+ null, true, null, options, null); >+ } >+ } finally { >+ System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "false"); >+ } >+ >+ } > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=346038 > public void test070a() throws Exception { > if (this.complianceLevel < ClassFileConstants.JDK1_5) return; >@@ -2835,6 +3039,52 @@ > }, > "Done"); > } >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383780 >+ public void test070a_tolerate() throws Exception { >+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; >+ Map options = getCompilerOptions(); >+ try { >+ System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "true"); >+ if (this.complianceLevel < ClassFileConstants.JDK1_7) { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static <T> void foo(int ...i) {}\n" + >+ " public static <T> void foo(double...d) {}\n" + >+ " public static void main(String[] args) {\n" + >+ " foo(1, 2, 3);\n" + >+ " System.out.println (\"Done\");\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " foo(1, 2, 3);\n" + >+ " ^^^\n" + >+ "The method foo(int[]) is ambiguous for the type X\n" + >+ "----------\n", >+ null, true, options); >+ } else { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static <T> void foo(int ...i) {}\n" + >+ " public static <T> void foo(double...d) {}\n" + >+ " public static void main(String[] args) {\n" + >+ " foo(1, 2, 3);\n" + >+ " System.out.println (\"Done\");\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "Done", >+ null, true, null, options, null); >+ } >+ } finally { >+ System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "false"); >+ } >+ } > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=346038 > public void test070b() throws Exception { > if (this.complianceLevel < ClassFileConstants.JDK1_5) return; >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java >index 1a2b75f..5fda025 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java >@@ -414,6 +414,19 @@ > public boolean analyseResourceLeaks; > /** Should missing enum cases be reported even if a default case exists in the same switch? */ > public boolean reportMissingEnumCaseDespiteDefault; >+ >+ /** Should the compiler tolerate illegal ambiguous varargs invocation in compliance < 1.7 >+ * to be bug compatible with javac? (bug 383780) */ >+ public boolean tolerateIllegalAmbiguousVarargsInvocation; >+ >+ { >+ String tolerateIllegalAmbiguousVarargs = System.getProperty("tolerateIllegalAmbiguousVarargsInvocation"); //$NON-NLS-1$ >+ if (tolerateIllegalAmbiguousVarargs != null && tolerateIllegalAmbiguousVarargs.equalsIgnoreCase("true")) { //$NON-NLS-1$ >+ this.tolerateIllegalAmbiguousVarargsInvocation = true; >+ } else { >+ this.tolerateIllegalAmbiguousVarargsInvocation = false; >+ } >+ } > > // keep in sync with warningTokenToIrritant and warningTokenFromIrritant > public final static String[] warningTokens = { >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 25fee09..a6b8c00 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 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2011 IBM Corporation and others. >+ * Copyright (c) 2000, 2012 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -582,6 +582,9 @@ > } > > int compatibilityLevel; >+ CompilerOptions options = this.compilerOptions(); >+ if (options.complianceLevel < ClassFileConstants.JDK1_7 && options.tolerateIllegalAmbiguousVarargsInvocation) >+ tiebreakingVarargsMethods = false; > if ((compatibilityLevel = parameterCompatibilityLevel(method, arguments, tiebreakingVarargsMethods)) > NOT_COMPATIBLE) { > if (compatibilityLevel == VARARGS_COMPATIBLE) { > TypeBinding varargsElementType = method.parameters[method.parameters.length - 1].leafComponentType(); >@@ -3029,8 +3032,14 @@ > if (i == oneParamsLength - 1 && one.isVarargs() && two.isVarargs()) { > TypeBinding oType = ((ArrayBinding) oneParam).elementsType(); > TypeBinding eType = ((ArrayBinding) twoParam).elementsType(); >- if (oType == eType || oType.isCompatibleWith(eType)) >- return true; // special case to choose between 2 varargs methods when the last arg is Object[] >+ CompilerOptions options = this.compilerOptions(); >+ if (options.complianceLevel < ClassFileConstants.JDK1_7 && options.tolerateIllegalAmbiguousVarargsInvocation) { >+ if (oneParam == eType || oneParam.isCompatibleWith(eType)) >+ return true; // special case to choose between 2 varargs methods when the last arg is Object[] >+ } else { >+ if (oType == eType || oType.isCompatibleWith(eType)) >+ return true; // special case to choose between 2 varargs methods when the last arg is Object[] >+ } > } > return false; > } >@@ -4092,7 +4101,8 @@ > // only called if env.options.sourceLevel >= ClassFileConstants.JDK1_5 > if (arg.isCompatibleWith(param)) > return COMPATIBLE; >- if (tieBreakingVarargsMethods) { >+ CompilerOptions options = this.compilerOptions(); >+ if (tieBreakingVarargsMethods && (options.complianceLevel >= ClassFileConstants.JDK1_7 || !options.tolerateIllegalAmbiguousVarargsInvocation)) { > /* 15.12.2.5 Choosing the Most Specific Method, ... One variable arity member method named m is more specific than > another variable arity member method of the same name if either ... Only subtypes relationship should be used. > Actually this is true even for fixed arity methods, but in practice is not an issue since we run the algorithm
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 383780
:
218230
|
218240
|
218319
|
218320
|
218798
|
219412