FIR: handle double-imported constructors properly
This commit is contained in:
+24
-8
@@ -73,15 +73,17 @@ internal fun FirScope.processFunctionsAndConstructorsByName(
|
||||
processFunctionsByName(callInfo.name, processor)
|
||||
}
|
||||
|
||||
private data class SymbolWithSubstitutor(val symbol: FirClassifierSymbol<*>, val substitutor: ConeSubstitutor)
|
||||
|
||||
private fun FirScope.getFirstClassifierOrNull(
|
||||
callInfo: CallInfo,
|
||||
session: FirSession,
|
||||
bodyResolveComponents: BodyResolveComponents
|
||||
): Pair<FirClassifierSymbol<*>, ConeSubstitutor>? {
|
||||
): SymbolWithSubstitutor? {
|
||||
var isSuccessResult = false
|
||||
var isAmbiguousResult = false
|
||||
var result: Pair<FirClassifierSymbol<*>, ConeSubstitutor>? = null
|
||||
processClassifiersByNameWithSubstitution(callInfo.name) { symbol, substitution ->
|
||||
var result: SymbolWithSubstitutor? = null
|
||||
processClassifiersByNameWithSubstitution(callInfo.name) { symbol, substitutor ->
|
||||
val classifierDeclaration = symbol.fir
|
||||
var isSuccessCandidate = true
|
||||
if (classifierDeclaration is FirMemberDeclaration) {
|
||||
@@ -103,11 +105,25 @@ private fun FirScope.getFirstClassifierOrNull(
|
||||
isSuccessCandidate = false
|
||||
}
|
||||
|
||||
if (result == null || (!isSuccessResult && isSuccessCandidate)) {
|
||||
isSuccessResult = isSuccessCandidate
|
||||
result = symbol to substitution
|
||||
} else {
|
||||
isAmbiguousResult = true
|
||||
when {
|
||||
isSuccessCandidate && !isSuccessResult -> {
|
||||
// any result is better than no result
|
||||
isSuccessResult = true
|
||||
result = SymbolWithSubstitutor(symbol, substitutor)
|
||||
}
|
||||
result?.symbol === symbol -> {
|
||||
// miss identical results
|
||||
return@processClassifiersByNameWithSubstitution
|
||||
}
|
||||
result != null -> {
|
||||
// results are similar => ambiguity
|
||||
isAmbiguousResult = true
|
||||
}
|
||||
else -> {
|
||||
// result == null: any result is better than no result
|
||||
isSuccessResult = isSuccessCandidate
|
||||
result = SymbolWithSubstitutor(symbol, substitutor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
// FILE: StarImported.kt
|
||||
|
||||
package star
|
||||
|
||||
class SomeClass
|
||||
|
||||
fun foo() {}
|
||||
|
||||
val bar = 1
|
||||
|
||||
// FILE: ExplicitImported.kt
|
||||
|
||||
package explicit
|
||||
|
||||
class AnotherClass
|
||||
|
||||
fun baz() {}
|
||||
|
||||
val gau = 2
|
||||
|
||||
// FILE: Test.kt
|
||||
|
||||
import star.*
|
||||
import star.*
|
||||
import explicit.<!CONFLICTING_IMPORT!>AnotherClass<!>
|
||||
import explicit.<!CONFLICTING_IMPORT!>AnotherClass<!>
|
||||
import explicit.baz
|
||||
import explicit.baz
|
||||
import explicit.gau
|
||||
import explicit.gau
|
||||
|
||||
fun useSomeClass(): SomeClass = <!RESOLUTION_TO_CLASSIFIER!>SomeClass<!>()
|
||||
|
||||
fun useAnotherClass(): AnotherClass = <!RESOLUTION_TO_CLASSIFIER!>AnotherClass<!>()
|
||||
|
||||
fun test() {
|
||||
foo()
|
||||
baz()
|
||||
val x = bar
|
||||
val y = gau
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// FILE: StarImported.kt
|
||||
|
||||
package star
|
||||
|
||||
Reference in New Issue
Block a user