Conflicting imports error for imports of classes and packages
This commit is contained in:
@@ -103,7 +103,7 @@ public interface Errors {
|
||||
DiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> CANNOT_BE_IMPORTED = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<JetExpression> USELESS_HIDDEN_IMPORT = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
DiagnosticFactory1<JetExpression, String> CONFLICTING_IMPORT = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<JetExpression> USELESS_SIMPLE_IMPORT = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
// Modifiers
|
||||
|
||||
+1
@@ -169,6 +169,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(CANNOT_IMPORT_FROM_ELEMENT, "Cannot import from ''{0}''", NAME);
|
||||
MAP.put(CANNOT_BE_IMPORTED, "Cannot import ''{0}'', functions and properties can be imported only from packages", NAME);
|
||||
MAP.put(USELESS_HIDDEN_IMPORT, "Useless import, it is hidden further");
|
||||
MAP.put(CONFLICTING_IMPORT, "Conflicting import, imported name ''{0}'' is ambiguous", STRING);
|
||||
MAP.put(USELESS_SIMPLE_IMPORT, "Useless import, does nothing");
|
||||
MAP.put(PLATFORM_CLASS_MAPPED_TO_KOTLIN, "This class shouldn''t be used in Kotlin. Use {0} instead.", CLASSES_OR_SEPARATED);
|
||||
|
||||
|
||||
@@ -175,13 +175,10 @@ public class ImportsResolver {
|
||||
) {
|
||||
|
||||
JetExpression importedReference = importDirective.getImportedReference();
|
||||
if (importedReference == null || resolvedTo == null) {
|
||||
return;
|
||||
}
|
||||
if (importedReference == null || resolvedTo == null) return;
|
||||
|
||||
Name aliasName = JetPsiUtil.getAliasName(importDirective);
|
||||
if (aliasName == null) {
|
||||
return;
|
||||
}
|
||||
if (aliasName == null) return;
|
||||
|
||||
boolean uselessHiddenImport = true;
|
||||
for (DeclarationDescriptor target : resolvedTo) {
|
||||
@@ -202,6 +199,23 @@ public class ImportsResolver {
|
||||
if (uselessHiddenImport) {
|
||||
trace.report(USELESS_HIDDEN_IMPORT.on(importedReference));
|
||||
}
|
||||
else {
|
||||
if (resolvedTo.size() == 1) {
|
||||
DeclarationDescriptor target = resolvedTo.iterator().next();
|
||||
if (target instanceof ClassDescriptor) {
|
||||
if (fileScope.getClassifier(aliasName) == null) {
|
||||
trace.report(CONFLICTING_IMPORT.on(importedReference, aliasName.asString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (target instanceof PackageViewDescriptor) {
|
||||
if (fileScope.getPackage(aliasName) == null) {
|
||||
trace.report(CONFLICTING_IMPORT.on(importedReference, aliasName.asString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!importDirective.isAllUnder() &&
|
||||
importedReference instanceof JetSimpleNameExpression &&
|
||||
|
||||
@@ -11,7 +11,7 @@ class X
|
||||
// FILE: c.kt
|
||||
package c
|
||||
|
||||
import a.X
|
||||
import b.X
|
||||
import <!CONFLICTING_IMPORT!>a.X<!>
|
||||
import <!CONFLICTING_IMPORT!>b.X<!>
|
||||
|
||||
class Y : <!UNRESOLVED_REFERENCE!>X<!>
|
||||
@@ -0,0 +1,17 @@
|
||||
// FILE: a.kt
|
||||
package a.x
|
||||
|
||||
class X
|
||||
|
||||
// FILE: b.kt
|
||||
package b.x
|
||||
|
||||
class X
|
||||
|
||||
// FILE: c.kt
|
||||
package c
|
||||
|
||||
import <!CONFLICTING_IMPORT!>a.x<!>
|
||||
import <!CONFLICTING_IMPORT!>b.x<!>
|
||||
|
||||
class Y : <!UNRESOLVED_REFERENCE!>x<!>.<!DEBUG_INFO_MISSING_UNRESOLVED!>X<!>
|
||||
@@ -0,0 +1,37 @@
|
||||
package
|
||||
|
||||
package a {
|
||||
|
||||
package a.x {
|
||||
|
||||
internal final class X {
|
||||
public constructor X()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
package b {
|
||||
|
||||
package b.x {
|
||||
|
||||
internal final class X {
|
||||
public constructor X()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
package c {
|
||||
|
||||
internal final class Y {
|
||||
public constructor Y()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
@@ -4739,6 +4739,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ExplicitPackageImportsAmbiguity.kt")
|
||||
public void testExplicitPackageImportsAmbiguity() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/ExplicitPackageImportsAmbiguity.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("importFunctionWithAllUnderImport.kt")
|
||||
public void testImportFunctionWithAllUnderImport() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/importFunctionWithAllUnderImport.kt");
|
||||
|
||||
@@ -129,6 +129,7 @@ public class QuickFixRegistrar {
|
||||
JetSingleIntentionActionFactory removeImportFixFactory = RemovePsiElementSimpleFix.createRemoveImportFactory();
|
||||
QuickFixes.factories.put(USELESS_SIMPLE_IMPORT, removeImportFixFactory);
|
||||
QuickFixes.factories.put(USELESS_HIDDEN_IMPORT, removeImportFixFactory);
|
||||
QuickFixes.factories.put(CONFLICTING_IMPORT, removeImportFixFactory);
|
||||
|
||||
QuickFixes.factories.put(SUPERTYPE_NOT_INITIALIZED, ChangeToConstructorInvocationFix.createFactory());
|
||||
QuickFixes.factories.put(FUNCTION_CALL_EXPECTED, ChangeToFunctionInvocationFix.createFactory());
|
||||
|
||||
Reference in New Issue
Block a user