diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/FileScopeProviderImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/FileScopeProviderImpl.kt index 9e8f7ab2949..66436216b4e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/FileScopeProviderImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/FileScopeProviderImpl.kt @@ -16,8 +16,10 @@ package org.jetbrains.kotlin.resolve.lazy -import org.jetbrains.kotlin.descriptors.ModuleDescriptor +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtImportDirective import org.jetbrains.kotlin.psi.KtImportsFactory @@ -25,13 +27,11 @@ import org.jetbrains.kotlin.resolve.BindingTrace import org.jetbrains.kotlin.resolve.QualifiedExpressionResolver import org.jetbrains.kotlin.resolve.TemporaryBindingTrace import org.jetbrains.kotlin.resolve.bindingContextUtil.recordScope -import org.jetbrains.kotlin.resolve.scopes.ImportingScope -import org.jetbrains.kotlin.resolve.scopes.LexicalScope -import org.jetbrains.kotlin.resolve.scopes.SubpackagesImportingScope +import org.jetbrains.kotlin.resolve.scopes.* import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.getValue -import org.jetbrains.kotlin.utils.sure +import org.jetbrains.kotlin.utils.Printer open class FileScopeProviderImpl( private val topLevelDescriptorProvider: TopLevelDescriptorProvider, @@ -100,7 +100,7 @@ open class FileScopeProviderImpl( scope = SubpackagesImportingScope(scope, moduleDescriptor, FqName.ROOT) - scope = packageView.memberScope.memberScopeAsImportingScope(scope) //TODO: problems with visibility too + scope = packageMemberScopeWithAliasedNamesExcluded(packageView, aliasImportNames).memberScopeAsImportingScope(scope) //TODO: problems with visibility too scope = LazyImportScope(scope, explicitImportResolver, LazyImportScope.FilteringKind.ALL, "Explicit imports in $debugName") @@ -126,4 +126,38 @@ open class FileScopeProviderImpl( return FileData(lexicalScope, importResolver) } + + private fun packageMemberScopeWithAliasedNamesExcluded(packageView: PackageViewDescriptor, aliasImportNames: Collection): MemberScope { + val scope = packageView.memberScope + if (aliasImportNames.isEmpty()) return scope + + val packageName = packageView.fqName + val excludedNames = aliasImportNames.mapNotNull { if (it.parent() == packageName) it.shortName() else null } + if (excludedNames.isEmpty()) return scope + + return object: MemberScope { + override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? { + if (name in excludedNames) return null + return scope.getContributedClassifier(name, location) + } + + override fun getContributedVariables(name: Name, location: LookupLocation): Collection { + if (name in excludedNames) return emptyList() + return scope.getContributedVariables(name, location) + } + + override fun getContributedFunctions(name: Name, location: LookupLocation): Collection { + if (name in excludedNames) return emptyList() + return scope.getContributedFunctions(name, location) + } + + override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection { + return scope.getContributedDescriptors(kindFilter, { name -> name !in excludedNames && nameFilter(name) }) + } + + override fun printScopeStructure(p: Printer) { + return scope.printScopeStructure(p) + } + } + } } diff --git a/compiler/testData/diagnostics/tests/imports/ImportFromCurrentWithDifferentName.kt b/compiler/testData/diagnostics/tests/imports/ImportFromCurrentWithDifferentName.kt index 08d4242283a..987118c19c0 100644 --- a/compiler/testData/diagnostics/tests/imports/ImportFromCurrentWithDifferentName.kt +++ b/compiler/testData/diagnostics/tests/imports/ImportFromCurrentWithDifferentName.kt @@ -3,6 +3,6 @@ package a import a.A as ER interface A { - val a: A + val a: A val b: ER } diff --git a/compiler/testData/diagnostics/tests/imports/ImportFromCurrentWithDifferentName.txt b/compiler/testData/diagnostics/tests/imports/ImportFromCurrentWithDifferentName.txt index 37b79e25bc2..f86d2217848 100644 --- a/compiler/testData/diagnostics/tests/imports/ImportFromCurrentWithDifferentName.txt +++ b/compiler/testData/diagnostics/tests/imports/ImportFromCurrentWithDifferentName.txt @@ -3,7 +3,7 @@ package package a { public interface A { - public abstract val a: a.A + public abstract val a: [ERROR : A] public abstract val b: a.A public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 602ac52763f..242872d3053 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -19003,7 +19003,7 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { @TestMetadata("compiler/testData/codegen/box/diagnostics/vararg") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) - public static class Vararg extends AbstractDiagnosticsTest { + public static class IIImpoiVararg extends AbstractDiagnosticsTest { public void testAllFilesPresentInVararg() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/diagnostics/vararg"), Pattern.compile("^(.+)\\.kt$"), true); }