diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeOverloadConflictResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeOverloadConflictResolver.kt index bbb032cf203..4a54310807c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeOverloadConflictResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeOverloadConflictResolver.kt @@ -61,7 +61,7 @@ class ConeOverloadConflictResolver( return FlatSignature( call, constructor.typeParameters.map { it.symbol }, - call.argumentMapping!!.map { it.value.argumentType() }, + computeParameterTypes(call, constructor), //constructor.receiverTypeRef != null, false, constructor.valueParameters.any { it.isVararg }, @@ -78,15 +78,10 @@ class ConeOverloadConflictResolver( } private fun createFlatSignature(call: Candidate, function: FirSimpleFunction): FlatSignature { - val valueParametersTypes = - call.resultingTypeForCallableReference?.typeArguments?.map { it as ConeKotlinType } - ?: (listOfNotNull(function.receiverTypeRef?.coneTypeUnsafe()) + - call.argumentMapping?.map { it.value.argumentType() }.orEmpty()) - return FlatSignature( call, function.typeParameters.map { it.symbol }, - valueParametersTypes, + computeParameterTypes(call, function), function.receiverTypeRef != null, function.valueParameters.any { it.isVararg }, function.valueParameters.count { it.defaultValue != null }, @@ -95,6 +90,15 @@ class ConeOverloadConflictResolver( ) } + private fun computeParameterTypes( + call: Candidate, + function: FirFunction<*> + ): List { + return (call.resultingTypeForCallableReference?.typeArguments?.map { it as ConeKotlinType } + ?: (listOfNotNull(function.receiverTypeRef?.coneTypeUnsafe()) + + call.argumentMapping?.map { it.value.argumentType() }.orEmpty())) + } + private fun createFlatSignature(call: Candidate, variable: FirVariable<*>): FlatSignature { return FlatSignature( call, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt index bb2881a4901..bf3223b4791 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt @@ -190,7 +190,7 @@ internal object CheckCallableReferenceExpectedType : CheckerStage() { val returnTypeRef = candidate.bodyResolveComponents.returnTypeCalculator.tryCalculateReturnType(fir) val resultingType: ConeKotlinType = when (fir) { - is FirSimpleFunction -> createKFunctionType(fir, resultingReceiverType, returnTypeRef) + is FirFunction -> createKFunctionType(fir, resultingReceiverType, returnTypeRef) is FirProperty -> createKPropertyType(fir, resultingReceiverType, returnTypeRef) else -> ConeKotlinErrorType("Unknown callable kind: ${fir::class}") }.let(candidate.substitutor::substituteOrSelf) @@ -242,7 +242,7 @@ private fun createKPropertyType( } private fun createKFunctionType( - function: FirSimpleFunction, + function: FirFunction<*>, receiverType: ConeKotlinType?, returnTypeRef: FirResolvedTypeRef ): ConeKotlinType { diff --git a/compiler/fir/resolve/testData/diagnostics/callableReferences/constructors.kt b/compiler/fir/resolve/testData/diagnostics/callableReferences/constructors.kt new file mode 100644 index 00000000000..df35a76d4c3 --- /dev/null +++ b/compiler/fir/resolve/testData/diagnostics/callableReferences/constructors.kt @@ -0,0 +1,10 @@ +class Klass { + constructor(a: Int) {} + constructor(a: String) {} +} + +fun user(f: (Int) -> Klass) {} + +fun fn() { + user(::Klass) +} diff --git a/compiler/fir/resolve/testData/diagnostics/callableReferences/constructors.txt b/compiler/fir/resolve/testData/diagnostics/callableReferences/constructors.txt new file mode 100644 index 00000000000..d6587033234 --- /dev/null +++ b/compiler/fir/resolve/testData/diagnostics/callableReferences/constructors.txt @@ -0,0 +1,16 @@ +FILE: constructors.kt + public final class Klass : R|kotlin/Any| { + public constructor(a: R|kotlin/Int|): R|Klass| { + super() + } + + public constructor(a: R|kotlin/String|): R|Klass| { + super() + } + + } + public final fun user(f: R|kotlin/Function1|): R|kotlin/Unit| { + } + public final fun fn(): R|kotlin/Unit| { + R|/user|(::R|/Klass.Klass|) + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index bdfc615e658..50f4c49db02 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -50,6 +50,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/resolve/testData/diagnostics/callableReferences/companions.kt"); } + @TestMetadata("constructors.kt") + public void testConstructors() throws Exception { + runTest("compiler/fir/resolve/testData/diagnostics/callableReferences/constructors.kt"); + } + @TestMetadata("differentLevels.kt") public void testDifferentLevels() throws Exception { runTest("compiler/fir/resolve/testData/diagnostics/callableReferences/differentLevels.kt");