mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-10 15:52:06 +00:00
Never import object descriptors, for they may overwrite corresponding vals
This commit is contained in:
@@ -148,6 +148,7 @@ public interface Importer {
|
||||
|
||||
@Override
|
||||
public void addAliasImport(@NotNull DeclarationDescriptor descriptor, @NotNull Name aliasName) {
|
||||
assert !DescriptorUtils.isObject(descriptor) : "Never import objects: " + descriptor;
|
||||
imports.add(new AliasImportEntry(descriptor, aliasName));
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,9 @@ public class QualifiedExpressionResolver {
|
||||
}
|
||||
|
||||
for (DeclarationDescriptor descriptor : descriptors) {
|
||||
importer.addAliasImport(descriptor, aliasName);
|
||||
if (!DescriptorUtils.isObject(descriptor)) {
|
||||
importer.addAliasImport(descriptor, aliasName);
|
||||
}
|
||||
}
|
||||
|
||||
return descriptors;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// FILE: a.kt
|
||||
|
||||
package foo
|
||||
|
||||
object Bar {
|
||||
fun bar() {}
|
||||
}
|
||||
|
||||
// FILE: b.kt
|
||||
|
||||
package baz
|
||||
|
||||
import foo.Bar
|
||||
|
||||
class C: <!UNRESOLVED_REFERENCE!>Bar<!>
|
||||
|
||||
fun test() {
|
||||
Bar.bar()
|
||||
}
|
||||
@@ -5419,6 +5419,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
doTest("compiler/testData/diagnostics/tests/scopes/ImportFromCurrentWithDifferentName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ImportObjectAndUseAsSupertype.kt")
|
||||
public void testImportObjectAndUseAsSupertype() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/scopes/ImportObjectAndUseAsSupertype.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ImportObjectHidesCurrentPackage.kt")
|
||||
public void testImportObjectHidesCurrentPackage() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/scopes/ImportObjectHidesCurrentPackage.kt");
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.utils.Printer;
|
||||
|
||||
@@ -215,6 +216,10 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
||||
public void importClassifierAlias(@NotNull Name importedClassifierName, @NotNull ClassifierDescriptor classifierDescriptor) {
|
||||
checkMayWrite();
|
||||
|
||||
if (DescriptorUtils.isObject(classifierDescriptor)) {
|
||||
throw new IllegalStateException("must not be object: " + classifierDescriptor);
|
||||
}
|
||||
|
||||
getCurrentIndividualImportScope().addClassifierAlias(importedClassifierName, classifierDescriptor);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user