diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt index d38c7e1fa8d..4404bc9a0bb 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt @@ -228,11 +228,11 @@ internal object CheckCallableReferenceExpectedType : CheckerStage() { // callable reference. // TODO: should refer to LanguageVersionSettings.SuspendConversion val requireSuspendConversion = expectedType?.isSuspendFunctionType(callInfo.session) == true - // TODO: handle callable reference with vararg val resultingType: ConeKotlinType = when (fir) { - is FirFunction -> callInfo.session.createKFunctionType( + is FirFunction -> callInfo.session.createAdaptedKFunctionType( + callInfo.session, fir, resultingReceiverType, returnTypeRef, - expectedParameterNumberWithReceiver = expectedType?.let { it.typeArguments.size - 1 }, + expectedParameterTypes = expectedType?.typeArguments, isSuspend = (fir as? FirSimpleFunction)?.isSuspend == true || requireSuspendConversion, expectedReturnType = extractInputOutputTypesFromCallableReferenceExpectedType(expectedType, callInfo.session)?.outputType ) @@ -286,27 +286,67 @@ private fun createKPropertyType( ) } -private fun FirSession.createKFunctionType( +private fun FirSession.createAdaptedKFunctionType( + session: FirSession, function: FirFunction<*>, receiverType: ConeKotlinType?, returnTypeRef: FirResolvedTypeRef, - expectedParameterNumberWithReceiver: Int?, + expectedParameterTypes: Array?, isSuspend: Boolean, expectedReturnType: ConeKotlinType? ): ConeKotlinType { // The similar adaptations: defaults and coercion-to-unit happen at org.jetbrains.kotlin.resolve.calls.components.CallableReferencesCandidateFactory.getCallableReferenceAdaptation val parameterTypes = mutableListOf() - val expectedParameterNumber = when { - expectedParameterNumberWithReceiver == null -> null - receiverType != null -> expectedParameterNumberWithReceiver - 1 - else -> expectedParameterNumberWithReceiver - } + val shift = if (receiverType != null) 1 else 0 + val expectedParameterNumber = + if (expectedParameterTypes == null) null + // Drop the last one: return type, and the first one: receiver type, if needed + else expectedParameterTypes.size - 1 - shift + + fun ConeKotlinType?.isPotentiallyArray(): Boolean = + this != null && (this.arrayElementType() != null || this is ConeTypeVariableType) + + var lastVarargParameter: FirValueParameter? = null for ((index, valueParameter) in function.valueParameters.withIndex()) { - if (expectedParameterNumber == null || - index < expectedParameterNumber || - (valueParameter.defaultValue == null && !valueParameter.isVararg) - ) { + // Update the last vararg parameter in preparation for adaptation. + if (valueParameter.isVararg) { + lastVarargParameter = valueParameter + } + // Pack value parameters until the expected parameter number is met. + if (expectedParameterNumber == null || index < expectedParameterNumber) { + // But, if the value parameter is vararg, make sure it matches with the expected parameter type. + if (expectedParameterTypes != null && valueParameter.isVararg) { + val expectedParameterType = (expectedParameterTypes[index + shift] as? ConeKotlinTypeProjection)?.type + if (!expectedParameterType.isPotentiallyArray()) { + // Expect an element. Will spread vararg parameter later. + continue + } + } parameterTypes += valueParameter.returnTypeRef.coneType + continue + } + // After expected parameters are fulfilled, a value parameter which doesn't have a default value or isn't vararg should be added to + // the resulting type (so that it can reject incompatible function reference). In either case, we can't assume no actual arguments + // are given. + if (valueParameter.defaultValue == null && !valueParameter.isVararg) { + parameterTypes += valueParameter.returnTypeRef.coneType + } + } + + // If a function with vararg is passed to a place where a spread of elements is expected, we can adapt the function reference to + // literally spread such vararg argument. E.g., foo(vararg xs: Char): String => bar(::foo) where bar(f: (Char, Char) -> String) + if (expectedParameterNumber != null && expectedParameterTypes != null && parameterTypes.size < expectedParameterNumber && lastVarargParameter != null) { + val varargArrayType = lastVarargParameter.returnTypeRef.coneType + val varargElementType = varargArrayType.varargElementType(session) + val expectedParameterType = (expectedParameterTypes[parameterTypes.size + shift] as? ConeKotlinTypeProjection)?.type + // Expect an array or potentially array (i.e., type variable). Pass vararg parameter as-is. + if (expectedParameterType.isPotentiallyArray()) { + parameterTypes += varargArrayType + } else { + // Expect an element. Spread vararg parameter. + while (parameterTypes.size < expectedParameterNumber) { + parameterTypes += varargElementType + } } } @@ -317,7 +357,8 @@ private fun FirSession.createKFunctionType( returnTypeRef.type return createFunctionalType( - parameterTypes, receiverType = receiverType, + parameterTypes, + receiverType = receiverType, rawReturnType = returnType, isKFunctionType = true, isSuspend = isSuspend diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/innerConstructorWithVararg.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/innerConstructorWithVararg.kt index 836250e00fa..d30f9487ba1 100644 --- a/compiler/testData/codegen/box/callableReference/adaptedReferences/innerConstructorWithVararg.kt +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/innerConstructorWithVararg.kt @@ -1,6 +1,4 @@ // !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType -// IGNORE_BACKEND_FIR: JVM_IR - class Outer(val o: String) { inner class Inner1(val i: Int, vararg v: String) { diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/largeVararg.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/largeVararg.kt index bc14da0c82b..ca32a3a831b 100644 --- a/compiler/testData/codegen/box/callableReference/adaptedReferences/largeVararg.kt +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/largeVararg.kt @@ -1,5 +1,4 @@ // !LANGUAGE: +NewInference -// IGNORE_BACKEND_FIR: JVM_IR fun foo( f: ( diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/localFunctionWithDefault.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/localFunctionWithDefault.kt index 5ffc9ea741e..733f4167d74 100644 --- a/compiler/testData/codegen/box/callableReference/adaptedReferences/localFunctionWithDefault.kt +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/localFunctionWithDefault.kt @@ -1,5 +1,4 @@ // !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType -// IGNORE_BACKEND_FIR: JVM_IR fun call0(f: (String) -> String, x: String): String = f(x) fun call1(f: (String, String) -> String, x: String, y: String): String = f(x, y) diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/varargViewedAsPrimitiveArray.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/varargViewedAsPrimitiveArray.kt index 39ddb43bdc0..d811287c073 100644 --- a/compiler/testData/codegen/box/callableReference/adaptedReferences/varargViewedAsPrimitiveArray.kt +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/varargViewedAsPrimitiveArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // !LANGUAGE: +NewInference fun sum(vararg args: Int): Int { diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/varargWithDefaultValue.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/varargWithDefaultValue.kt index 435ed1162ea..9cca54c03e7 100644 --- a/compiler/testData/codegen/box/callableReference/adaptedReferences/varargWithDefaultValue.kt +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/varargWithDefaultValue.kt @@ -1,5 +1,4 @@ // !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType -// IGNORE_BACKEND_FIR: JVM_IR fun foo(x: Int, s: Int, vararg y: CharSequence = arrayOf("Aaa")): String = if (y.size == s && y[0].length == x) "OK" else "Fail" diff --git a/compiler/testData/codegen/box/callableReference/serializability/adaptedReferences.kt b/compiler/testData/codegen/box/callableReference/serializability/adaptedReferences.kt index d0fd6af8708..89736604ce4 100644 --- a/compiler/testData/codegen/box/callableReference/serializability/adaptedReferences.kt +++ b/compiler/testData/codegen/box/callableReference/serializability/adaptedReferences.kt @@ -1,5 +1,4 @@ // TARGET_BACKEND: JVM -// IGNORE_BACKEND_FIR: JVM_IR // WITH_REFLECT import java.io.* diff --git a/compiler/testData/diagnostics/tests/callableReference/genericCallWithReferenceAgainstVararg.fir.kt b/compiler/testData/diagnostics/tests/callableReference/genericCallWithReferenceAgainstVararg.fir.kt index b904f79d1e3..0129151a7b0 100644 --- a/compiler/testData/diagnostics/tests/callableReference/genericCallWithReferenceAgainstVararg.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/genericCallWithReferenceAgainstVararg.fir.kt @@ -7,7 +7,7 @@ fun test(i: IntArray) { myLet(::foo) myLet(::foo) myLet(::foo) - myLetExplicit1(::foo) + myLetExplicit1(::foo) myLetExplicit2(::foo) } diff --git a/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.fir.kt b/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.fir.kt index 5d649d045aa..1670fcd336d 100644 --- a/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.fir.kt @@ -36,7 +36,7 @@ object Test3 { fun test() { val result = foo(::bar) - result + result } } } diff --git a/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationHasDependencyOnApi14.fir.kt b/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationHasDependencyOnApi14.fir.kt index c3bd1b383a6..334312a0d3f 100644 --- a/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationHasDependencyOnApi14.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationHasDependencyOnApi14.fir.kt @@ -12,7 +12,7 @@ fun allOfTheAbove(f: (A) -> Unit): Any = f fun test() { coercionToUnit(A::foo) - varargToElement(A::foo) + varargToElement(A::foo) defaultAndVararg(A::foo) allOfTheAbove(A::foo) } diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/withVararg.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/withVararg.fir.kt index 364e0e57ca7..25fc9de9f5d 100644 --- a/compiler/testData/diagnostics/tests/callableReference/resolve/withVararg.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/withVararg.fir.kt @@ -6,5 +6,5 @@ fun foo(i: Int) {} val fn1: (Int) -> Unit = ::foo val fn2: (IntArray) -> Unit = ::foo -val fn3: (Int, Int) -> Unit = ::foo +val fn3: (Int, Int) -> Unit = ::foo val fn4: (Array) -> Unit = ::foo \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suspendConversion/suspendConversionWithReferenceAdaptation.fir.kt b/compiler/testData/diagnostics/tests/suspendConversion/suspendConversionWithReferenceAdaptation.fir.kt deleted file mode 100644 index 823d1ce01f1..00000000000 --- a/compiler/testData/diagnostics/tests/suspendConversion/suspendConversionWithReferenceAdaptation.fir.kt +++ /dev/null @@ -1,21 +0,0 @@ -// !LANGUAGE: +SuspendConversion -// !DIAGNOSTICS: -UNUSED_PARAMETER - -fun unitCoercion(f: suspend () -> Unit) {} -fun foo(): Int = 0 - -fun defaults(f: suspend (Int) -> String) {} -fun bar(i: Int, l: Long = 42L): String = "" - -fun varargs(f: suspend (Int, Int, Int) -> String) {} -fun baz(vararg ints: Int): String = "" - -fun unitCoercionAndDefaults(f: suspend () -> Unit) {} -fun all(s: String = ""): Int = 0 - -fun test() { - unitCoercion(::foo) - defaults(::bar) - varargs(::baz) - unitCoercionAndDefaults(::all) -} diff --git a/compiler/testData/diagnostics/tests/suspendConversion/suspendConversionWithReferenceAdaptation.kt b/compiler/testData/diagnostics/tests/suspendConversion/suspendConversionWithReferenceAdaptation.kt index 73f5ea5fa48..0b12740a3d5 100644 --- a/compiler/testData/diagnostics/tests/suspendConversion/suspendConversionWithReferenceAdaptation.kt +++ b/compiler/testData/diagnostics/tests/suspendConversion/suspendConversionWithReferenceAdaptation.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +SuspendConversion // !DIAGNOSTICS: -UNUSED_PARAMETER diff --git a/compiler/testData/diagnostics/tests/varargs/varargViewedAsArray.fir.kt b/compiler/testData/diagnostics/tests/varargs/varargViewedAsArray.fir.kt index 6d630d02642..44ae0640029 100644 --- a/compiler/testData/diagnostics/tests/varargs/varargViewedAsArray.fir.kt +++ b/compiler/testData/diagnostics/tests/varargs/varargViewedAsArray.fir.kt @@ -17,13 +17,13 @@ fun useMixedStringArgs3(fn: (String, Array, String) -> Unit) = fn("foo", fun useTwoStringArrays(fn: (Array, Array) -> Unit) = fn(arrayOf("foo", "bar"), arrayOf("baz", "boo")) fun test() { - useStrings(::stringVararg) + useStrings(::stringVararg) useStringArray(::stringVararg) useIntArray(::numberVararg) usePrimitiveIntArray(::intVararg) useIntArray(::intVararg) useMixedStringArgs1(::stringVararg) - useMixedStringArgs2(::stringVararg) + useMixedStringArgs2(::stringVararg) useMixedStringArgs3(::stringVararg) - useTwoStringArrays(::stringVararg) + useTwoStringArrays(::stringVararg) } diff --git a/compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.fir.txt index 20403a99e73..764aeb4d34d 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.fir.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.fir.txt @@ -37,5 +37,5 @@ FILE fqName: fileName:/adaptedWithCoercionToUnit.kt FUN name:testV1 visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testV1 (): kotlin.Unit declared in ' - ERROR_CALL 'Unresolved reference: #' type=kotlin.Unit - ERROR_CALL 'Unsupported callable reference: ::#' type=IrErrorType + CALL 'public final fun useUnit1 (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUNCTION_REFERENCE 'public final fun fnv (vararg xs: kotlin.Int): kotlin.Int declared in ' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= diff --git a/compiler/testData/ir/irText/expressions/callableReferences/constructorWithAdaptedArguments.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/constructorWithAdaptedArguments.fir.txt index 933352ca8c9..f90cf4c1f31 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/constructorWithAdaptedArguments.fir.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/constructorWithAdaptedArguments.fir.txt @@ -69,16 +69,18 @@ FILE fqName: fileName:/constructorWithAdaptedArguments.kt FUN name:testConstructor visibility:public modality:FINAL <> () returnType:kotlin.Any BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testConstructor (): kotlin.Any declared in ' - ERROR_CALL 'Unresolved reference: #' type=kotlin.Any - ERROR_CALL 'Unsupported callable reference: ::#' type=IrErrorType + CALL 'public final fun use (fn: kotlin.Function1): kotlin.Any declared in ' type=kotlin.Any origin=null + fn: FUNCTION_REFERENCE 'public constructor (vararg xs: kotlin.Int) [primary] declared in .C' type=kotlin.reflect.KFunction1.C> origin=null reflectionTarget= FUN name:testInnerClassConstructor visibility:public modality:FINAL <> (outer:.Outer) returnType:kotlin.Any VALUE_PARAMETER name:outer index:0 type:.Outer BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testInnerClassConstructor (outer: .Outer): kotlin.Any declared in ' - ERROR_CALL 'Unresolved reference: #' type=kotlin.Any - ERROR_CALL 'Unsupported callable reference: R|/outer|::#' type=IrErrorType + CALL 'public final fun use (fn: kotlin.Function1): kotlin.Any declared in ' type=kotlin.Any origin=null + fn: FUNCTION_REFERENCE 'public constructor (vararg xs: kotlin.Int) [primary] declared in .Outer.Inner' type=kotlin.reflect.KFunction1.Outer.Inner> origin=null reflectionTarget= + $this: GET_VAR 'outer: .Outer declared in .testInnerClassConstructor' type=.Outer origin=null FUN name:testInnerClassConstructorCapturingOuter visibility:public modality:FINAL <> () returnType:kotlin.Any BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testInnerClassConstructorCapturingOuter (): kotlin.Any declared in ' - ERROR_CALL 'Unresolved reference: #' type=kotlin.Any - ERROR_CALL 'Unsupported callable reference: R|/Outer.Outer|()::#' type=IrErrorType + CALL 'public final fun use (fn: kotlin.Function1): kotlin.Any declared in ' type=kotlin.Any origin=null + fn: FUNCTION_REFERENCE 'public constructor (vararg xs: kotlin.Int) [primary] declared in .Outer.Inner' type=kotlin.reflect.KFunction1.Outer.Inner> origin=null reflectionTarget= + $this: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Outer' type=.Outer origin=null diff --git a/compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.fir.txt index 5827e995583..6f83550b68c 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.fir.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.fir.txt @@ -82,8 +82,12 @@ FILE fqName: fileName:/suspendConversion.kt CALL 'public final fun foo2 (vararg xs: kotlin.Int): kotlin.Unit declared in ' type=kotlin.Unit origin=null FUN name:testWithVarargMapped visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=kotlin.Unit - ERROR_CALL 'Unsupported callable reference: ::#' type=IrErrorType + CALL 'public final fun useSuspendInt (fn: kotlin.coroutines.SuspendFunction1): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUN_EXPR type=kotlin.coroutines.SuspendFunction1 origin=ADAPTED_FUNCTION_REFERENCE + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo2 visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit [suspend] + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int + BLOCK_BODY + CALL 'public final fun foo2 (vararg xs: kotlin.Int): kotlin.Unit declared in ' type=kotlin.Unit origin=null FUN name:testWithCoercionToUnit visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public final fun useSuspend (fn: kotlin.coroutines.SuspendFunction0): kotlin.Unit declared in ' type=kotlin.Unit origin=null diff --git a/compiler/testData/ir/irText/expressions/callableReferences/unboundMemberReferenceWithAdaptedArguments.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/unboundMemberReferenceWithAdaptedArguments.fir.txt index 0efda6e1405..9c822812070 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/unboundMemberReferenceWithAdaptedArguments.fir.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/unboundMemberReferenceWithAdaptedArguments.fir.txt @@ -59,14 +59,16 @@ FILE fqName: fileName:/unboundMemberReferenceWithAdaptedArguments.kt $this: VALUE_PARAMETER name: type:kotlin.Any FUN name:testUnbound visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=kotlin.Unit - ERROR_CALL 'Unsupported callable reference: Q|A|::#' type=IrErrorType + CALL 'public final fun use1 (fn: kotlin.Function2<.A, kotlin.Int, kotlin.Unit>): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUNCTION_REFERENCE 'public open fun foo (vararg xs: kotlin.Int): kotlin.Int declared in .A' type=kotlin.reflect.KFunction2<.A, kotlin.Int, kotlin.Unit> origin=null reflectionTarget= FUN name:testBound visibility:public modality:FINAL <> (a:.A) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:.A BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=kotlin.Unit - ERROR_CALL 'Unsupported callable reference: R|/a|::#' type=IrErrorType + CALL 'public final fun use2 (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUNCTION_REFERENCE 'public open fun foo (vararg xs: kotlin.Int): kotlin.Int declared in .A' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= + $this: GET_VAR 'a: .A declared in .testBound' type=.A origin=null FUN name:testObject visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=kotlin.Unit - ERROR_CALL 'Unsupported callable reference: Q|Obj|::#' type=IrErrorType + CALL 'public final fun use2 (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUNCTION_REFERENCE 'public final fun foo (vararg xs: kotlin.Int): kotlin.Int declared in .Obj' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= + $this: GET_OBJECT 'CLASS OBJECT name:Obj modality:FINAL visibility:public superTypes:[.A]' type=.Obj diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.fir.txt index 4bdbb17c700..66ffdfe69de 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.fir.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.fir.txt @@ -27,5 +27,6 @@ FILE fqName: fileName:/withAdaptationForSam.kt CONST Int type=kotlin.Int value=42 FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=kotlin.Unit - ERROR_CALL 'Unsupported callable reference: ::#' type=IrErrorType + CALL 'public final fun useFoo (foo: .IFoo): kotlin.Unit declared in ' type=kotlin.Unit origin=null + foo: TYPE_OP type=.IFoo origin=SAM_CONVERSION typeOperand=.IFoo + FUNCTION_REFERENCE 'public final fun withVararg (vararg xs: kotlin.Int): kotlin.Int declared in ' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.fir.txt index e59ee184b04..1b9d9b745c0 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.fir.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.fir.txt @@ -71,8 +71,8 @@ FILE fqName: fileName:/withAdaptedArguments.kt FUN name:testVararg visibility:public modality:FINAL <> () returnType:kotlin.String BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testVararg (): kotlin.String declared in ' - ERROR_CALL 'Unresolved reference: #' type=kotlin.String - ERROR_CALL 'Unsupported callable reference: ::#' type=IrErrorType + CALL 'public final fun use (fn: kotlin.Function1): kotlin.String declared in ' type=kotlin.String origin=null + fn: FUNCTION_REFERENCE 'public final fun fnWithVarargs (vararg xs: kotlin.Int): kotlin.String declared in ' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= FUN name:testCoercionToUnit visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testCoercionToUnit (): kotlin.Unit declared in ' @@ -81,8 +81,9 @@ FILE fqName: fileName:/withAdaptedArguments.kt FUN name:testImportedObjectMember visibility:public modality:FINAL <> () returnType:kotlin.String BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testImportedObjectMember (): kotlin.String declared in ' - ERROR_CALL 'Unresolved reference: #' type=kotlin.String - ERROR_CALL 'Unsupported callable reference: ::#' type=IrErrorType + CALL 'public final fun use (fn: kotlin.Function1): kotlin.String declared in ' type=kotlin.String origin=null + fn: FUNCTION_REFERENCE 'public final fun importedObjectMemberWithVarargs (vararg xs: kotlin.Int): kotlin.String declared in .Host' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= + $this: GET_OBJECT 'CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Host FUN name:testDefault0 visibility:public modality:FINAL <> () returnType:kotlin.String BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testDefault0 (): kotlin.String declared in ' diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withArgumentAdaptationAndReceiver.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/withArgumentAdaptationAndReceiver.fir.txt index 9ab9953e080..f56077c7b6f 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/withArgumentAdaptationAndReceiver.fir.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/withArgumentAdaptationAndReceiver.fir.txt @@ -20,33 +20,38 @@ FILE fqName: fileName:/withArgumentAdaptationAndReceiver.kt FUN name:testImplicitThis visibility:public modality:FINAL <> ($this:.Host) returnType:kotlin.Unit $this: VALUE_PARAMETER name: type:.Host BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=kotlin.Unit - ERROR_CALL 'Unsupported callable reference: ::#' type=IrErrorType + CALL 'public final fun use (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUNCTION_REFERENCE 'public final fun withVararg (vararg xs: kotlin.Int): kotlin.String declared in .Host' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= + $this: GET_VAR ': .Host declared in .Host.testImplicitThis' type=.Host origin=null FUN name:testBoundReceiverLocalVal visibility:public modality:FINAL <> ($this:.Host) returnType:kotlin.Unit $this: VALUE_PARAMETER name: type:.Host BLOCK_BODY VAR name:h type:.Host [val] CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Host' type=.Host origin=null - ERROR_CALL 'Unresolved reference: #' type=kotlin.Unit - ERROR_CALL 'Unsupported callable reference: R|/h|::#' type=IrErrorType + CALL 'public final fun use (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUNCTION_REFERENCE 'public final fun withVararg (vararg xs: kotlin.Int): kotlin.String declared in .Host' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= + $this: GET_VAR 'val h: .Host [val] declared in .Host.testBoundReceiverLocalVal' type=.Host origin=null FUN name:testBoundReceiverLocalVar visibility:public modality:FINAL <> ($this:.Host) returnType:kotlin.Unit $this: VALUE_PARAMETER name: type:.Host BLOCK_BODY VAR name:h type:.Host [var] CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Host' type=.Host origin=null - ERROR_CALL 'Unresolved reference: #' type=kotlin.Unit - ERROR_CALL 'Unsupported callable reference: R|/h|::#' type=IrErrorType + CALL 'public final fun use (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUNCTION_REFERENCE 'public final fun withVararg (vararg xs: kotlin.Int): kotlin.String declared in .Host' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= + $this: GET_VAR 'var h: .Host [var] declared in .Host.testBoundReceiverLocalVar' type=.Host origin=null FUN name:testBoundReceiverParameter visibility:public modality:FINAL <> ($this:.Host, h:.Host) returnType:kotlin.Unit $this: VALUE_PARAMETER name: type:.Host VALUE_PARAMETER name:h index:0 type:.Host BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=kotlin.Unit - ERROR_CALL 'Unsupported callable reference: R|/h|::#' type=IrErrorType + CALL 'public final fun use (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUNCTION_REFERENCE 'public final fun withVararg (vararg xs: kotlin.Int): kotlin.String declared in .Host' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= + $this: GET_VAR 'h: .Host declared in .Host.testBoundReceiverParameter' type=.Host origin=null FUN name:testBoundReceiverExpression visibility:public modality:FINAL <> ($this:.Host) returnType:kotlin.Unit $this: VALUE_PARAMETER name: type:.Host BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=kotlin.Unit - ERROR_CALL 'Unsupported callable reference: R|/Host.Host|()::#' type=IrErrorType + CALL 'public final fun use (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUNCTION_REFERENCE 'public final fun withVararg (vararg xs: kotlin.Int): kotlin.String declared in .Host' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= + $this: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Host' type=.Host origin=null FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withVarargViewedAsArray.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/withVarargViewedAsArray.fir.txt index e482286b7be..02d1b261b0c 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/withVarargViewedAsArray.fir.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/withVarargViewedAsArray.fir.txt @@ -60,8 +60,8 @@ FILE fqName: fileName:/withVarargViewedAsArray.kt BLOCK_BODY FUN name:testPlainArgs visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=kotlin.Unit - ERROR_CALL 'Unsupported callable reference: ::#' type=IrErrorType + CALL 'public final fun usePlainArgs (fn: kotlin.Function2): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUNCTION_REFERENCE 'public final fun sum (vararg args: kotlin.Int): kotlin.Int declared in ' type=kotlin.reflect.KFunction2 origin=null reflectionTarget= FUN name:testPrimitiveArrayAsVararg visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public final fun usePrimitiveArray (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null diff --git a/compiler/testData/ir/irText/expressions/funInterface/samConversionInVarargs.fir.txt b/compiler/testData/ir/irText/expressions/funInterface/samConversionInVarargs.fir.txt index bbc5a28e03e..d397ac785b5 100644 --- a/compiler/testData/ir/irText/expressions/funInterface/samConversionInVarargs.fir.txt +++ b/compiler/testData/ir/irText/expressions/funInterface/samConversionInVarargs.fir.txt @@ -59,5 +59,6 @@ FILE fqName: fileName:/samConversionInVarargs.kt CONST String type=kotlin.String value="" FUN name:testAdaptedCR visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=kotlin.Unit - ERROR_CALL 'Unsupported callable reference: ::#' type=IrErrorType + CALL 'public final fun useVararg (vararg foos: .IFoo): kotlin.Unit declared in ' type=kotlin.Unit origin=null + foos: VARARG type=kotlin.Array.IFoo> varargElementType=.IFoo + FUNCTION_REFERENCE 'public final fun withVarargOfInt (vararg xs: kotlin.Int): kotlin.String declared in ' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= diff --git a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/resolving-callable-references/bidirectional-resolution-for-callable-calls/p-3/pos/1.4.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/resolving-callable-references/bidirectional-resolution-for-callable-calls/p-3/pos/1.4.fir.kt index 58000bc1618..0628e99016d 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/resolving-callable-references/bidirectional-resolution-for-callable-calls/p-3/pos/1.4.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/resolving-callable-references/bidirectional-resolution-for-callable-calls/p-3/pos/1.4.fir.kt @@ -28,10 +28,10 @@ class Case2() { } fun case() { - foo(::invoke, ::invoke) - foo(::invoke, ::invoke) - foo(::invoke, ::invoke) - foo(::invoke, ::invoke) + foo(")!>::invoke, ")!>::invoke) + foo(::invoke, ::invoke) + foo(::invoke, ::invoke) + foo(::invoke, ::invoke) } fun foo(vararg x: (Int)->Any): String = TODO() // (1.1)