K2: Fix incorrect UNRESOLVED_REFERENCE after aliased import in other file
The problem is actually caused by 60f09f6512
It happened because we've been caching package scope using FqName key,
so once one file contains aliased import it would work like other file
contains it, too.
So, the fix is adding excludedNames to the key, too.
^KT-59789 Fixed
This commit is contained in:
committed by
Space Team
parent
b18b2abe05
commit
f37dc27974
+1
-5
@@ -24,16 +24,12 @@ class FirPackageMemberScope(
|
||||
val fqName: FqName,
|
||||
val session: FirSession,
|
||||
private val symbolProvider: FirSymbolProvider = session.symbolProvider,
|
||||
excludedImportNames: Collection<FqName>? = null,
|
||||
private val excludedNames: Set<Name> = emptySet(),
|
||||
) : FirScope() {
|
||||
private val classifierCache: MutableMap<Name, FirClassifierSymbol<*>?> = mutableMapOf()
|
||||
private val functionCache: MutableMap<Name, List<FirNamedFunctionSymbol>> = mutableMapOf()
|
||||
private val propertyCache: MutableMap<Name, List<FirPropertySymbol>> = mutableMapOf()
|
||||
|
||||
private val excludedNames by lazy {
|
||||
excludedImportNames?.mapNotNullTo(mutableSetOf()) { if (it.parent() == fqName) it.shortName() else null }.orEmpty()
|
||||
}
|
||||
|
||||
override fun processClassifiersByNameWithSubstitution(
|
||||
name: Name,
|
||||
processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit
|
||||
|
||||
@@ -18,7 +18,6 @@ import org.jetbrains.kotlin.name.FqName
|
||||
private val ALL_IMPORTS = scopeSessionKey<FirFile, ListStorageFirScope>()
|
||||
private val DEFAULT_STAR_IMPORT = scopeSessionKey<DefaultStarImportKey, FirDefaultStarImportingScope>()
|
||||
private val DEFAULT_SIMPLE_IMPORT = scopeSessionKey<DefaultImportPriority, FirDefaultSimpleImportingScope>()
|
||||
|
||||
private data class DefaultStarImportKey(val priority: DefaultImportPriority, val excludedImportNames: Set<FqName>)
|
||||
|
||||
fun createImportingScopes(
|
||||
@@ -42,6 +41,12 @@ private fun doCreateImportingScopes(
|
||||
file.lazyResolveToPhase(FirResolvePhase.IMPORTS)
|
||||
val excludedImportNames =
|
||||
file.imports.filter { it.aliasName != null }.mapNotNullTo(hashSetOf()) { it.importedFqName }.ifEmpty { emptySet() }
|
||||
|
||||
val excludedNamesInPackage =
|
||||
excludedImportNames.mapNotNullTo(mutableSetOf()) {
|
||||
if (it.parent() == file.packageFqName) it.shortName() else null
|
||||
}
|
||||
|
||||
return listOf(
|
||||
scopeSession.getOrBuild(DefaultStarImportKey(DefaultImportPriority.LOW, excludedImportNames), DEFAULT_STAR_IMPORT) {
|
||||
FirDefaultStarImportingScope(session, scopeSession, DefaultImportPriority.LOW, excludedImportNames)
|
||||
@@ -60,8 +65,14 @@ private fun doCreateImportingScopes(
|
||||
scopeSession.getOrBuild(DefaultImportPriority.HIGH, DEFAULT_SIMPLE_IMPORT) {
|
||||
FirDefaultSimpleImportingScope(session, scopeSession, priority = DefaultImportPriority.HIGH)
|
||||
},
|
||||
scopeSession.getOrBuild(file.packageFqName, PACKAGE_MEMBER) {
|
||||
FirPackageMemberScope(file.packageFqName, session, excludedImportNames = excludedImportNames)
|
||||
when {
|
||||
excludedNamesInPackage.isEmpty() ->
|
||||
// Supposed to be the most common branch, so we cache it
|
||||
scopeSession.getOrBuild(file.packageFqName, PACKAGE_MEMBER) {
|
||||
FirPackageMemberScope(file.packageFqName, session, excludedNames = emptySet())
|
||||
}
|
||||
else ->
|
||||
FirPackageMemberScope(file.packageFqName, session, excludedNames = excludedNamesInPackage)
|
||||
},
|
||||
// TODO: explicit simple importing scope should have highest priority (higher than inner scopes added in process)
|
||||
FirExplicitSimpleImportingScope(file.imports, session, scopeSession)
|
||||
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
// ISSUE: KT-59789
|
||||
// FILE: a/A.java
|
||||
package a;
|
||||
public interface A {}
|
||||
|
||||
// FILE: first.kt
|
||||
package b
|
||||
import b.DependencyAnalyzerDependency as Dependency
|
||||
|
||||
fun foo(d: Dependency) {}
|
||||
|
||||
// FILE: main.kt
|
||||
package b
|
||||
|
||||
import a.A
|
||||
interface DependencyAnalyzerDependency : A {
|
||||
val parent: <!UNRESOLVED_REFERENCE!>DependencyAnalyzerDependency<!>? // Should be resolved
|
||||
}
|
||||
|
||||
fun bar(d: <!UNRESOLVED_REFERENCE!>DependencyAnalyzerDependency<!>) {
|
||||
foo(d)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// ISSUE: KT-59789
|
||||
// FILE: a/A.java
|
||||
package a;
|
||||
|
||||
Reference in New Issue
Block a user