8133616: compiler error messages for dup single type, single static import switched
authorjlahoda
Mon, 27 Nov 2017 19:29:00 +0100
changeset 47948 8b11e4b32db3
parent 47947 5dab5e8f06a3
child 47949 002e99dd12f2
8133616: compiler error messages for dup single type, single static import switched Summary: When reporting clashing imports, use the (non-)staticness of the original import to generate the error message. Reviewed-by: mcimadamore
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
test/langtools/jdk/jshell/ForwardReferenceImportTest.java
test/langtools/tools/javac/4980495/std/NonStatic2StaticImportClash.java
test/langtools/tools/javac/4980495/std/Static2NonStaticImportClash.java
test/langtools/tools/javac/diags/examples/AlreadyDefinedStaticImport/AlreadDefinedStaticImport.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Tue Nov 28 07:58:32 2017 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Mon Nov 27 19:29:00 2017 +0100
@@ -3557,18 +3557,19 @@
                                       Scope staticallyImportedSoFar, Scope topLevelScope,
                                       Symbol sym, boolean staticImport) {
         Filter<Symbol> duplicates = candidate -> candidate != sym && !candidate.type.isErroneous();
-        Symbol clashing = ordinallyImportedSoFar.findFirst(sym.name, duplicates);
-        if (clashing == null && !staticImport) {
-            clashing = staticallyImportedSoFar.findFirst(sym.name, duplicates);
+        Symbol ordinaryClashing = ordinallyImportedSoFar.findFirst(sym.name, duplicates);
+        Symbol staticClashing = null;
+        if (ordinaryClashing == null && !staticImport) {
+            staticClashing = staticallyImportedSoFar.findFirst(sym.name, duplicates);
         }
-        if (clashing != null) {
-            if (staticImport)
-                log.error(pos, Errors.AlreadyDefinedStaticSingleImport(clashing));
+        if (ordinaryClashing != null || staticClashing != null) {
+            if (ordinaryClashing != null)
+                log.error(pos, Errors.AlreadyDefinedSingleImport(ordinaryClashing));
             else
-                log.error(pos, Errors.AlreadyDefinedSingleImport(clashing));
+                log.error(pos, Errors.AlreadyDefinedStaticSingleImport(staticClashing));
             return false;
         }
-        clashing = topLevelScope.findFirst(sym.name, duplicates);
+        Symbol clashing = topLevelScope.findFirst(sym.name, duplicates);
         if (clashing != null) {
             log.error(pos, Errors.AlreadyDefinedThisUnit(clashing));
             return false;
--- a/test/langtools/jdk/jshell/ForwardReferenceImportTest.java	Tue Nov 28 07:58:32 2017 +0100
+++ b/test/langtools/jdk/jshell/ForwardReferenceImportTest.java	Mon Nov 27 19:29:00 2017 +0100
@@ -188,7 +188,7 @@
                 DiagCheck.DIAG_ERROR,
                 added(VALID),
                 ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
-        assertDeclareFail("A.list = Arrays.asList(1, 2, 3);", "compiler.err.already.defined.static.single.import");
+        assertDeclareFail("A.list = Arrays.asList(1, 2, 3);", "compiler.err.already.defined.single.import");
         assertActiveKeys();
         assertDrop(list,
                 ste(list, VALID, DROPPED, true, null),
--- a/test/langtools/tools/javac/4980495/std/NonStatic2StaticImportClash.java	Tue Nov 28 07:58:32 2017 +0100
+++ b/test/langtools/tools/javac/4980495/std/NonStatic2StaticImportClash.java	Mon Nov 27 19:29:00 2017 +0100
@@ -1,14 +1,14 @@
 /*
  * @test  /nodynamiccopyright/
- * @bug 7101822
+ * @bug 7101822 8133616
  * @summary Check the when clashing types are imported through an ordinary and static import,
  *          the compile-time error is properly reported.
  * @compile/fail/ref=NonStatic2StaticImportClash.out -XDrawDiagnostics NonStatic2StaticImportClash.java p1/A1.java p2/A2.java
  *
  */
 
-import p1.A1.f;
-import static p2.A2.f;
+import static p1.A1.f;
+import p2.A2.f;
 
 public class NonStatic2StaticImportClash {
 }
--- a/test/langtools/tools/javac/4980495/std/Static2NonStaticImportClash.java	Tue Nov 28 07:58:32 2017 +0100
+++ b/test/langtools/tools/javac/4980495/std/Static2NonStaticImportClash.java	Mon Nov 27 19:29:00 2017 +0100
@@ -1,14 +1,14 @@
 /*
  * @test  /nodynamiccopyright/
- * @bug 7101822
+ * @bug 7101822 8133616
  * @summary Check the when clashing types are imported through an ordinary and static import,
  *          the compile-time error is properly reported.
  * @compile/fail/ref=Static2NonStaticImportClash.out -XDrawDiagnostics Static2NonStaticImportClash.java p1/A1.java p2/A2.java
  *
  */
 
-import static p2.A2.f;
-import p1.A1.f;
+import p2.A2.f;
+import static p1.A1.f;
 
 public class Static2NonStaticImportClash {
 }
--- a/test/langtools/tools/javac/diags/examples/AlreadyDefinedStaticImport/AlreadDefinedStaticImport.java	Tue Nov 28 07:58:32 2017 +0100
+++ b/test/langtools/tools/javac/diags/examples/AlreadyDefinedStaticImport/AlreadDefinedStaticImport.java	Mon Nov 27 19:29:00 2017 +0100
@@ -23,5 +23,5 @@
 
 // key: compiler.err.already.defined.static.single.import
 
-import p.E1.A;
-import static p.E2.A;
+import static p.E1.A;
+import p.E2.A;