diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/beyoundCalls.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/beyoundCalls.fir.txt index ca1ef7fcb91..36eb12f9c5e 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/beyoundCalls.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/beyoundCalls.fir.txt @@ -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: = ::# + lval y: R|kotlin/reflect/KFunction1| = ::R|/bar| lval z: R|kotlin/reflect/KFunction1| = ::R|/baz| lval w: R|(kotlin/String) -> kotlin/Int| = ::R|/foobaz| ::R|/baz| diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/beyoundCalls.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/beyoundCalls.kt index 0ffa0b95280..0ab5fc03b14 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/beyoundCalls.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/beyoundCalls.kt @@ -6,7 +6,7 @@ fun foobaz(x: T): R = TODO() fun foo() { val x: (String) -> Int = ::bar - val y = ::bar + val y = ::bar val z = ::baz val w: (String) -> Int = ::foobaz diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/resolve/calls/jvm/ConeEquivalentCallConflictResolver.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/resolve/calls/jvm/ConeEquivalentCallConflictResolver.kt index 61392fac9ac..e3e85fc130c 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/resolve/calls/jvm/ConeEquivalentCallConflictResolver.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/resolve/calls/jvm/ConeEquivalentCallConflictResolver.kt @@ -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) && diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/AbstractConeCallConflictResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/AbstractConeCallConflictResolver.kt index 0179ba6b12c..20e2ca2b343 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/AbstractConeCallConflictResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/AbstractConeCallConflictResolver.kt @@ -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 { 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() } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/removeTypeVariableTypes.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/TypeVariableTypeRemovingSubstitutor.kt similarity index 86% rename from compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/removeTypeVariableTypes.kt rename to compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/TypeVariableTypeRemovingSubstitutor.kt index 8dd632c6422..f6f84bad087 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/removeTypeVariableTypes.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/TypeVariableTypeRemovingSubstitutor.kt @@ -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) } diff --git a/compiler/testData/codegen/box/invokedynamic/sam/functionRefToJavaInterface/multifileClassMemberFromStdlib.kt b/compiler/testData/codegen/box/invokedynamic/sam/functionRefToJavaInterface/multifileClassMemberFromStdlib.kt index 1f7058687a1..f5c9846aa28 100644 --- a/compiler/testData/codegen/box/invokedynamic/sam/functionRefToJavaInterface/multifileClassMemberFromStdlib.kt +++ b/compiler/testData/codegen/box/invokedynamic/sam/functionRefToJavaInterface/multifileClassMemberFromStdlib.kt @@ -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, b: List, bf: BF) = diff --git a/compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.fir.kt b/compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.fir.kt index ca6fce68c13..2fe0def1097 100644 --- a/compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.fir.kt @@ -22,7 +22,7 @@ fun B.foo(): Double = 0.0 fun call(a: Any) {} fun testA(a: A) { - call(A::foo) + call(A::foo) call(A.Companion::foo) } diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWithBoundExtensionReceiver.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWithBoundExtensionReceiver.fir.kt deleted file mode 100644 index 91a83c25be8..00000000000 --- a/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWithBoundExtensionReceiver.fir.kt +++ /dev/null @@ -1,15 +0,0 @@ -// SKIP_TXT -// !LANGUAGE: +NewInference -// !DIAGNOSTICS: -UNUSED_PARAMETER -// !CHECK_TYPE - -fun bar(f: () -> R): R = TODO() - -fun Any.foo() = 1 -fun A.foo() = "" - -class A { - fun main() { - bar(::foo) checkType { _() } - } -} diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWithBoundExtensionReceiver.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWithBoundExtensionReceiver.kt index 62e99f697ce..43b964c33f7 100644 --- a/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWithBoundExtensionReceiver.kt +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWithBoundExtensionReceiver.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // SKIP_TXT // !LANGUAGE: +NewInference // !DIAGNOSTICS: -UNUSED_PARAMETER