Substitute type variables properly in ConeOverloadConflictResolver
#KT-46187 Fixed
This commit is contained in:
Vendored
+1
-1
@@ -13,7 +13,7 @@ FILE: beyoundCalls.kt
|
||||
}
|
||||
public final fun foo(): R|kotlin/Unit| {
|
||||
lval x: R|(kotlin/String) -> kotlin/Int| = ::R|/bar|
|
||||
lval y: <ERROR TYPE REF: Ambiguity: bar, [/bar, /bar]> = ::<Ambiguity: bar, [/bar, /bar]>#
|
||||
lval y: R|kotlin/reflect/KFunction1<kotlin/String, kotlin/Int>| = ::R|/bar|
|
||||
lval z: R|kotlin/reflect/KFunction1<kotlin/String, kotlin/Int>| = ::R|/baz|
|
||||
lval w: R|(kotlin/String) -> kotlin/Int| = ::R|/foobaz<kotlin/String, kotlin/Int>|
|
||||
::R|/baz|
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ fun <T, R> foobaz(x: T): R = TODO()
|
||||
|
||||
fun foo() {
|
||||
val x: (String) -> Int = ::bar
|
||||
val y = ::<!OVERLOAD_RESOLUTION_AMBIGUITY!>bar<!>
|
||||
val y = ::bar
|
||||
val z = ::baz
|
||||
val w: (String) -> Int = ::foobaz
|
||||
|
||||
|
||||
+3
@@ -59,6 +59,9 @@ class ConeEquivalentCallConflictResolver(
|
||||
if (first.receiverTypeRef?.coneType != second.receiverTypeRef?.coneType) {
|
||||
return false
|
||||
}
|
||||
if (first is FirVariable != second is FirVariable) {
|
||||
return false
|
||||
}
|
||||
val firstSignature = createFlatSignature(firstCandidate, first)
|
||||
val secondSignature = createFlatSignature(secondCandidate, second)
|
||||
return compareCallsByUsedArguments(firstSignature, secondSignature, false) &&
|
||||
|
||||
+9
-22
@@ -7,12 +7,8 @@ package org.jetbrains.kotlin.fir.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
|
||||
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.resolve.calls.results.*
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
@@ -116,7 +112,7 @@ abstract class AbstractConeCallConflictResolver(
|
||||
return FlatSignature(
|
||||
call,
|
||||
(variable as? FirProperty)?.typeParameters?.map { it.symbol.toLookupTag() }.orEmpty(),
|
||||
listOfNotNull(variable.receiverTypeRef?.coneType),
|
||||
computeSignatureTypes(call, variable),
|
||||
variable.receiverTypeRef != null,
|
||||
0, // TODO
|
||||
false,
|
||||
@@ -130,7 +126,7 @@ abstract class AbstractConeCallConflictResolver(
|
||||
return FlatSignature(
|
||||
call,
|
||||
constructor.typeParameters.map { it.symbol.toLookupTag() },
|
||||
computeParameterTypes(call, constructor),
|
||||
computeSignatureTypes(call, constructor),
|
||||
//constructor.receiverTypeRef != null,
|
||||
false,
|
||||
0, // TODO
|
||||
@@ -145,7 +141,7 @@ abstract class AbstractConeCallConflictResolver(
|
||||
return FlatSignature(
|
||||
call,
|
||||
function.typeParameters.map { it.symbol.toLookupTag() },
|
||||
computeParameterTypes(call, function),
|
||||
computeSignatureTypes(call, function),
|
||||
function.receiverTypeRef != null,
|
||||
0, // TODO
|
||||
function.valueParameters.any { it.isVararg },
|
||||
@@ -161,27 +157,18 @@ abstract class AbstractConeCallConflictResolver(
|
||||
return type
|
||||
}
|
||||
|
||||
private fun computeParameterTypes(
|
||||
private fun computeSignatureTypes(
|
||||
call: Candidate,
|
||||
function: FirFunction
|
||||
called: FirCallableDeclaration
|
||||
): List<ConeKotlinType> {
|
||||
return buildList {
|
||||
addIfNotNull(function.receiverTypeRef?.coneType)
|
||||
addIfNotNull(called.receiverTypeRef?.coneType)
|
||||
val typeForCallableReference = call.resultingTypeForCallableReference
|
||||
if (typeForCallableReference != null) {
|
||||
typeForCallableReference.typeArguments
|
||||
// Return type isn't needed here v
|
||||
typeForCallableReference.typeArguments.dropLast(1)
|
||||
.mapTo(this) {
|
||||
when (it) {
|
||||
is ConeTypeVariableType -> {
|
||||
val typeParameterLookupTag = it.lookupTag.originalTypeParameter as ConeTypeParameterLookupTag?
|
||||
if (typeParameterLookupTag == null) {
|
||||
ConeErrorType(ConeSimpleDiagnostic("no type parameter for type variable", DiagnosticKind.Other))
|
||||
} else {
|
||||
ConeTypeParameterTypeImpl(typeParameterLookupTag, it.isNullable)
|
||||
}
|
||||
}
|
||||
else -> it as ConeKotlinType
|
||||
}
|
||||
(it as ConeKotlinType).removeTypeVariableTypes(inferenceComponents.session.typeContext)
|
||||
}
|
||||
} else {
|
||||
call.argumentMapping?.mapTo(this) { it.value.argumentType() }
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.diagnostics
|
||||
package org.jetbrains.kotlin.fir.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnknownLambdaParameterTypeDiagnostic
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.AbstractConeSubstitutor
|
||||
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
||||
|
||||
internal fun ConeKotlinType.removeTypeVariableTypes(typeContext: ConeTypeContext): ConeKotlinType {
|
||||
fun ConeKotlinType.removeTypeVariableTypes(typeContext: ConeTypeContext): ConeKotlinType {
|
||||
val substitutor = TypeVariableTypeRemovingSubstitutor(typeContext)
|
||||
return substitutor.substituteOrSelf(this)
|
||||
}
|
||||
-3
@@ -7,9 +7,6 @@
|
||||
// JVM_IR_TEMPLATES
|
||||
// 1 java/lang/invoke/LambdaMetafactory
|
||||
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// FIR status: OVERLOAD_RESOLUTION_AMBIGUITY: Overload resolution ambiguity between candidates: [kotlin/collections/plus, kotlin/collections/plus]
|
||||
|
||||
// FILE: multifileClassMemberFromStdlib.kt
|
||||
|
||||
fun test(a: List<String>, b: List<String>, bf: BF) =
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ fun B.foo(): Double = 0.0
|
||||
fun call(a: Any) {}
|
||||
|
||||
fun testA(a: A) {
|
||||
call(A::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>)
|
||||
call(A::foo)
|
||||
call(A.Companion::foo)
|
||||
}
|
||||
|
||||
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
// SKIP_TXT
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun <R> bar(f: () -> R): R = TODO()
|
||||
|
||||
fun Any.foo() = 1
|
||||
fun A.foo() = ""
|
||||
|
||||
class A {
|
||||
fun main() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>bar<!>(::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>) checkType { _<String>() }
|
||||
}
|
||||
}
|
||||
compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWithBoundExtensionReceiver.kt
Vendored
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// SKIP_TXT
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
Reference in New Issue
Block a user