[FIR] Fix "List has more than one element" for arrayOf call (workaround)
It happens because several builtins are loaded, but it should be only single builtin ^KT-60824 Fixed ^KTIJ-26465
This commit is contained in:
committed by
Space Team
parent
f989037f7c
commit
8a482c50c2
+17
-12
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.fir.resolve.calls.*
|
|||||||
import org.jetbrains.kotlin.fir.resolve.createErrorReferenceWithExistingCandidate
|
import org.jetbrains.kotlin.fir.resolve.createErrorReferenceWithExistingCandidate
|
||||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeAmbiguityError
|
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeAmbiguityError
|
||||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableCandidateError
|
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableCandidateError
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedNameError
|
||||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||||
import org.jetbrains.kotlin.fir.resolve.toErrorReference
|
import org.jetbrains.kotlin.fir.resolve.toErrorReference
|
||||||
import org.jetbrains.kotlin.fir.resolvedTypeFromPrototype
|
import org.jetbrains.kotlin.fir.resolvedTypeFromPrototype
|
||||||
@@ -71,7 +72,7 @@ class FirSyntheticCallGenerator(
|
|||||||
private val idFunction: FirSimpleFunction = generateSyntheticSelectFunction(SyntheticCallableId.ID)
|
private val idFunction: FirSimpleFunction = generateSyntheticSelectFunction(SyntheticCallableId.ID)
|
||||||
private val checkNotNullFunction: FirSimpleFunction = generateSyntheticCheckNotNullFunction()
|
private val checkNotNullFunction: FirSimpleFunction = generateSyntheticCheckNotNullFunction()
|
||||||
private val elvisFunction: FirSimpleFunction = generateSyntheticElvisFunction()
|
private val elvisFunction: FirSimpleFunction = generateSyntheticElvisFunction()
|
||||||
private val arrayOfSymbolCache: FirCache<Name, FirNamedFunctionSymbol, Nothing?> = session.firCachesFactory.createCache(::getArrayOfSymbol)
|
private val arrayOfSymbolCache: FirCache<Name, FirNamedFunctionSymbol?, Nothing?> = session.firCachesFactory.createCache(::getArrayOfSymbol)
|
||||||
|
|
||||||
private fun assertSyntheticResolvableReferenceIsNotResolved(resolvable: FirResolvable) {
|
private fun assertSyntheticResolvableReferenceIsNotResolved(resolvable: FirResolvable) {
|
||||||
// All synthetic calls (FirWhenExpression, FirTryExpression, FirElvisExpression, FirCheckNotNullCall)
|
// All synthetic calls (FirWhenExpression, FirTryExpression, FirElvisExpression, FirCheckNotNullCall)
|
||||||
@@ -177,19 +178,23 @@ class FirSyntheticCallGenerator(
|
|||||||
val argumentList = arrayLiteral.argumentList
|
val argumentList = arrayLiteral.argumentList
|
||||||
return buildFunctionCall {
|
return buildFunctionCall {
|
||||||
this.argumentList = argumentList
|
this.argumentList = argumentList
|
||||||
calleeReference = generateCalleeReferenceWithCandidate(
|
calleeReference = calculateArrayOfSymbol(expectedTypeRef)?.let {
|
||||||
arrayLiteral,
|
generateCalleeReferenceWithCandidate(
|
||||||
calculateArrayOfSymbol(expectedTypeRef).fir,
|
arrayLiteral,
|
||||||
argumentList,
|
it.fir,
|
||||||
ArrayFqNames.ARRAY_OF_FUNCTION,
|
argumentList,
|
||||||
callKind = CallKind.Function,
|
ArrayFqNames.ARRAY_OF_FUNCTION,
|
||||||
context = context,
|
callKind = CallKind.Function,
|
||||||
)
|
context = context,
|
||||||
|
)
|
||||||
|
} ?: buildErrorNamedReference {
|
||||||
|
diagnostic = ConeUnresolvedNameError(ArrayFqNames.ARRAY_OF_FUNCTION)
|
||||||
|
}
|
||||||
source = arrayLiteral.source
|
source = arrayLiteral.source
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateArrayOfSymbol(expectedTypeRef: FirTypeRef): FirNamedFunctionSymbol {
|
private fun calculateArrayOfSymbol(expectedTypeRef: FirTypeRef): FirNamedFunctionSymbol? {
|
||||||
val coneType = expectedTypeRef.coneType
|
val coneType = expectedTypeRef.coneType
|
||||||
val arrayCallName = when {
|
val arrayCallName = when {
|
||||||
coneType.isPrimitiveArray -> {
|
coneType.isPrimitiveArray -> {
|
||||||
@@ -208,10 +213,10 @@ class FirSyntheticCallGenerator(
|
|||||||
return arrayOfSymbolCache.getValue(arrayCallName)
|
return arrayOfSymbolCache.getValue(arrayCallName)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getArrayOfSymbol(arrayOfName: Name): FirNamedFunctionSymbol {
|
private fun getArrayOfSymbol(arrayOfName: Name): FirNamedFunctionSymbol? {
|
||||||
return session.symbolProvider
|
return session.symbolProvider
|
||||||
.getTopLevelFunctionSymbols(StandardNames.BUILT_INS_PACKAGE_FQ_NAME, arrayOfName)
|
.getTopLevelFunctionSymbols(StandardNames.BUILT_INS_PACKAGE_FQ_NAME, arrayOfName)
|
||||||
.single()
|
.firstOrNull() // TODO: it should be single() after KTIJ-26465 is fixed
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resolveCallableReferenceWithSyntheticOuterCall(
|
fun resolveCallableReferenceWithSyntheticOuterCall(
|
||||||
|
|||||||
Reference in New Issue
Block a user