8133616: compiler error messages for dup single type, single static import switched

When reporting clashing imports, use the (non-)staticness of the original import to generate the error message.

Reviewed-by: mcimadamore
This commit is contained in:
Jan Lahoda 2017-11-27 19:29:00 +01:00
parent df53288513
commit 9bb2c5a0b3
5 changed files with 18 additions and 17 deletions
src/jdk.compiler/share/classes/com/sun/tools/javac/comp
test/langtools

@ -3557,18 +3557,19 @@ public class Check {
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;

@ -188,7 +188,7 @@ public class ForwardReferenceImportTest extends KullaTesting {
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),

@ -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 {
}

@ -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 {
}

@ -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;