From d74168fb8f301ad303f153cf8a1f0484ff72bd2e Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 15 Mar 2021 18:57:52 +0300 Subject: [PATCH] PSI2IR KT-44414 fix adapted reference to imported object member --- .../FirBlackBoxCodegenTestGenerated.java | 6 ++ .../runners/ir/Fir2IrTextTestGenerated.java | 6 ++ .../ReflectionReferencesGenerator.kt | 38 +++++++---- .../adaptedVarargFunImportedFromObject.kt | 13 ++++ .../varargFunImportedFromObject.fir.txt | 64 ++++++++++++++++++ .../varargFunImportedFromObject.kt | 11 ++++ .../varargFunImportedFromObject.txt | 65 +++++++++++++++++++ .../withAdaptedArguments.kt.txt | 4 +- .../withAdaptedArguments.txt | 4 +- .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++ .../IrBlackBoxCodegenTestGenerated.java | 6 ++ .../test/runners/ir/IrTextTestGenerated.java | 6 ++ .../LightAnalysisModeTestGenerated.java | 5 ++ .../IrJsCodegenBoxES6TestGenerated.java | 5 ++ .../IrJsCodegenBoxTestGenerated.java | 5 ++ .../semantics/JsCodegenBoxTestGenerated.java | 5 ++ 16 files changed, 235 insertions(+), 14 deletions(-) create mode 100644 compiler/testData/codegen/box/callableReference/adaptedReferences/adaptedVarargFunImportedFromObject.kt create mode 100644 compiler/testData/ir/irText/expressions/callableReferences/varargFunImportedFromObject.fir.txt create mode 100644 compiler/testData/ir/irText/expressions/callableReferences/varargFunImportedFromObject.kt create mode 100644 compiler/testData/ir/irText/expressions/callableReferences/varargFunImportedFromObject.txt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 4d6313ba815..c918169bb55 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -2522,6 +2522,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT @TestMetadata("compiler/testData/codegen/box/callableReference/adaptedReferences") @TestDataPath("$PROJECT_ROOT") public class AdaptedReferences { + @Test + @TestMetadata("adaptedVarargFunImportedFromObject.kt") + public void testAdaptedVarargFunImportedFromObject() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/adaptedVarargFunImportedFromObject.kt"); + } + @Test public void testAllFilesPresentInAdaptedReferences() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/adaptedReferences"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java index 12675ff63eb..687af753201 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java @@ -1829,6 +1829,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/expressions/callableReferences/unboundMemberReferenceWithAdaptedArguments.kt"); } + @Test + @TestMetadata("varargFunImportedFromObject.kt") + public void testVarargFunImportedFromObject() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferences/varargFunImportedFromObject.kt"); + } + @Test @TestMetadata("withAdaptationForSam.kt") public void testWithAdaptationForSam() throws Exception { diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt index 27990538b3a..05b3dac008a 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt @@ -39,8 +39,8 @@ import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffsetSkippingComments import org.jetbrains.kotlin.psi2ir.intermediate.CallBuilder import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor import org.jetbrains.kotlin.resolve.calls.model.* -import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.expressions.DoubleColonLHS @@ -133,7 +133,15 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St val ktExpectedParameterTypes = ktFunctionalTypeArguments.take(ktFunctionalTypeArguments.size - 1).map { it.type } val irAdapterFun = - createAdapterFun(startOffset, endOffset, adapteeDescriptor, ktExpectedParameterTypes, ktExpectedReturnType, callBuilder, callableReferenceType) + createAdapterFun( + startOffset, + endOffset, + adapteeDescriptor, + ktExpectedParameterTypes, + ktExpectedReturnType, + callBuilder, + callableReferenceType + ) val irCall = createAdapteeCall(startOffset, endOffset, adapteeSymbol, callBuilder, irAdapterFun) irAdapterFun.body = context.irFactory.createBlockBody(startOffset, endOffset).apply { @@ -189,14 +197,17 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St val hasBoundDispatchReceiver = resolvedCall.dispatchReceiver != null && resolvedCall.dispatchReceiver !is TransientReceiver val hasBoundExtensionReceiver = resolvedCall.extensionReceiver != null && resolvedCall.extensionReceiver !is TransientReceiver - if (hasBoundDispatchReceiver || hasBoundExtensionReceiver) { + val isImportedFromObject = callBuilder.original.resultingDescriptor is ImportedFromObjectCallableDescriptor<*> + if (hasBoundDispatchReceiver || hasBoundExtensionReceiver || isImportedFromObject) { // In case of a bound reference, the receiver (which can only be one) is passed in the extension receiver parameter. val receiverValue = IrGetValueImpl( startOffset, endOffset, irAdapterFun.extensionReceiverParameter!!.symbol, IrStatementOrigin.ADAPTED_FUNCTION_REFERENCE ) when { - hasBoundDispatchReceiver -> irCall.dispatchReceiver = receiverValue - hasBoundExtensionReceiver -> irCall.extensionReceiver = receiverValue + hasBoundDispatchReceiver || isImportedFromObject -> + irCall.dispatchReceiver = receiverValue + hasBoundExtensionReceiver -> + irCall.extensionReceiver = receiverValue } } @@ -328,10 +339,10 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St irAdapterFun.dispatchReceiverParameter = null - val boundReceiver = callBuilder.original.selectBoundReceiver() - if (boundReceiver != null) { + val boundReceiverType = callBuilder.original.getBoundReceiverType() + if (boundReceiverType != null) { irAdapterFun.extensionReceiverParameter = - createAdapterParameter(startOffset, endOffset, Name.identifier("receiver"), -1, boundReceiver.type) + createAdapterParameter(startOffset, endOffset, Name.identifier("receiver"), -1, boundReceiverType) } else { irAdapterFun.extensionReceiverParameter = null } @@ -343,12 +354,17 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St } } - private fun ResolvedCall<*>.selectBoundReceiver(): ReceiverValue? { + private fun ResolvedCall<*>.getBoundReceiverType(): KotlinType? { + val descriptor = resultingDescriptor + if (descriptor is ImportedFromObjectCallableDescriptor<*>) { + return descriptor.containingObject.defaultType + } + val dispatchReceiver = dispatchReceiver.takeUnless { it is TransientReceiver } val extensionReceiver = extensionReceiver.takeUnless { it is TransientReceiver } return when { - dispatchReceiver == null -> extensionReceiver - extensionReceiver == null -> dispatchReceiver + dispatchReceiver == null -> extensionReceiver?.type + extensionReceiver == null -> dispatchReceiver.type else -> error("Bound callable references can't have both receivers: $resultingDescriptor") } } diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/adaptedVarargFunImportedFromObject.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/adaptedVarargFunImportedFromObject.kt new file mode 100644 index 00000000000..79d567ef63a --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/adaptedVarargFunImportedFromObject.kt @@ -0,0 +1,13 @@ +// DONT_TARGET_EXACT_BACKEND: WASM +// WASM_MUTE_REASON: BINDING_RECEIVERS +// IGNORE_BACKEND_FIR: JVM_IR + +import Host.foo + +fun withO(fn: (String) -> String) = fn("O") + +object Host { + fun foo(vararg x: String) = x[0] + "K" +} + +fun box() = withO(::foo) diff --git a/compiler/testData/ir/irText/expressions/callableReferences/varargFunImportedFromObject.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/varargFunImportedFromObject.fir.txt new file mode 100644 index 00000000000..fa7bd228346 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/varargFunImportedFromObject.fir.txt @@ -0,0 +1,64 @@ +FILE fqName: fileName:/varargFunImportedFromObject.kt + FUN name:withO visibility:public modality:FINAL <> (fn:kotlin.Function1) returnType:kotlin.String + VALUE_PARAMETER name:fn index:0 type:kotlin.Function1 + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun withO (fn: kotlin.Function1): kotlin.String declared in ' + CALL 'public abstract fun invoke (p1: P1 of kotlin.Function1): R of kotlin.Function1 [operator] declared in kotlin.Function1' type=kotlin.String origin=INVOKE + $this: GET_VAR 'fn: kotlin.Function1 declared in .withO' type=kotlin.Function1 origin=VARIABLE_AS_FUNCTION + p1: CONST String type=kotlin.String value="O" + CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Host + CONSTRUCTOR visibility:private <> () returnType:.Host [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:foo visibility:public modality:FINAL <> ($this:.Host, x:kotlin.Array) returnType:kotlin.String + $this: VALUE_PARAMETER name: type:.Host + VALUE_PARAMETER name:x index:0 type:kotlin.Array varargElementType:kotlin.String [vararg] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun foo (vararg x: kotlin.String): kotlin.String declared in .Host' + CONST String type=kotlin.String value="K" + 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 + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test1 (): kotlin.String declared in ' + CALL 'public final fun withO (fn: kotlin.Function1): kotlin.String declared in ' type=kotlin.String origin=null + fn: BLOCK type=kotlin.Function1 origin=ADAPTED_FUNCTION_REFERENCE + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo visibility:local modality:FINAL <> ($receiver:.Host, p0:kotlin.String) returnType:kotlin.String + $receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:receiver type:.Host + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun foo (p0: kotlin.String): kotlin.String declared in .test1' + CALL 'public final fun foo (vararg x: kotlin.String): kotlin.String declared in .Host' type=kotlin.String origin=null + $this: GET_VAR 'receiver: .Host declared in .test1.foo' type=.Host origin=ADAPTED_FUNCTION_REFERENCE + x: VARARG type=kotlin.Array varargElementType=kotlin.String + GET_VAR 'p0: kotlin.String declared in .test1.foo' type=kotlin.String origin=null + FUNCTION_REFERENCE 'local final fun foo (p0: kotlin.String): kotlin.String declared in .test1' type=kotlin.Function1 origin=ADAPTED_FUNCTION_REFERENCE reflectionTarget=null + FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test2 (): kotlin.String declared in ' + CALL 'public final fun withO (fn: kotlin.Function1): kotlin.String declared in ' type=kotlin.String origin=null + fn: BLOCK type=kotlin.Function1 origin=ADAPTED_FUNCTION_REFERENCE + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo visibility:local modality:FINAL <> ($receiver:.Host, p0:kotlin.String) returnType:kotlin.String + $receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:receiver type:.Host + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun foo (p0: kotlin.String): kotlin.String declared in .test2' + CALL 'public final fun foo (vararg x: kotlin.String): kotlin.String declared in .Host' type=kotlin.String origin=null + $this: GET_VAR 'receiver: .Host declared in .test2.foo' type=.Host origin=ADAPTED_FUNCTION_REFERENCE + x: VARARG type=kotlin.Array varargElementType=kotlin.String + GET_VAR 'p0: kotlin.String declared in .test2.foo' type=kotlin.String origin=null + FUNCTION_REFERENCE 'local final fun foo (p0: kotlin.String): kotlin.String declared in .test2' type=kotlin.Function1 origin=ADAPTED_FUNCTION_REFERENCE reflectionTarget=null + $receiver: GET_OBJECT 'CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Host diff --git a/compiler/testData/ir/irText/expressions/callableReferences/varargFunImportedFromObject.kt b/compiler/testData/ir/irText/expressions/callableReferences/varargFunImportedFromObject.kt new file mode 100644 index 00000000000..729a3ad27bc --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/varargFunImportedFromObject.kt @@ -0,0 +1,11 @@ +// SKIP_KT_DUMP +import Host.foo + +fun withO(fn: (String) -> String) = fn("O") + +object Host { + fun foo(vararg x: String) = "K" +} + +fun test1() = withO(::foo) +fun test2() = withO(Host::foo) diff --git a/compiler/testData/ir/irText/expressions/callableReferences/varargFunImportedFromObject.txt b/compiler/testData/ir/irText/expressions/callableReferences/varargFunImportedFromObject.txt new file mode 100644 index 00000000000..1bfc5a67007 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/varargFunImportedFromObject.txt @@ -0,0 +1,65 @@ +FILE fqName: fileName:/varargFunImportedFromObject.kt + FUN name:withO visibility:public modality:FINAL <> (fn:kotlin.Function1) returnType:kotlin.String + VALUE_PARAMETER name:fn index:0 type:kotlin.Function1 + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun withO (fn: kotlin.Function1): kotlin.String declared in ' + CALL 'public abstract fun invoke (p1: P1 of kotlin.Function1): R of kotlin.Function1 [operator] declared in kotlin.Function1' type=kotlin.String origin=INVOKE + $this: GET_VAR 'fn: kotlin.Function1 declared in .withO' type=kotlin.Function1 origin=VARIABLE_AS_FUNCTION + p1: CONST String type=kotlin.String value="O" + CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Host + CONSTRUCTOR visibility:private <> () returnType:.Host [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:foo visibility:public modality:FINAL <> ($this:.Host, x:kotlin.Array) returnType:kotlin.String + $this: VALUE_PARAMETER name: type:.Host + VALUE_PARAMETER name:x index:0 type:kotlin.Array varargElementType:kotlin.String [vararg] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun foo (vararg x: kotlin.String): kotlin.String declared in .Host' + CONST String type=kotlin.String value="K" + 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 + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test1 (): kotlin.String declared in ' + CALL 'public final fun withO (fn: kotlin.Function1): kotlin.String declared in ' type=kotlin.String origin=null + fn: BLOCK type=kotlin.Function1 origin=ADAPTED_FUNCTION_REFERENCE + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo visibility:local modality:FINAL <> ($receiver:.Host, p0:kotlin.String) returnType:kotlin.String + $receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:receiver type:.Host + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun foo (p0: kotlin.String): kotlin.String declared in .test1' + CALL 'public final fun foo (vararg x: kotlin.String): kotlin.String declared in .Host' type=kotlin.String origin=null + $this: GET_VAR 'receiver: .Host declared in .test1.foo' type=.Host origin=ADAPTED_FUNCTION_REFERENCE + x: VARARG type=kotlin.Array varargElementType=kotlin.String + GET_VAR 'p0: kotlin.String declared in .test1.foo' type=kotlin.String origin=null + FUNCTION_REFERENCE 'local final fun foo (p0: kotlin.String): kotlin.String declared in .test1' type=kotlin.Function1 origin=ADAPTED_FUNCTION_REFERENCE reflectionTarget=public final fun foo (vararg x: kotlin.String): kotlin.String declared in .Host + $receiver: GET_OBJECT 'CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Host + FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test2 (): kotlin.String declared in ' + CALL 'public final fun withO (fn: kotlin.Function1): kotlin.String declared in ' type=kotlin.String origin=null + fn: BLOCK type=kotlin.Function1 origin=ADAPTED_FUNCTION_REFERENCE + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo visibility:local modality:FINAL <> ($receiver:.Host, p0:kotlin.String) returnType:kotlin.String + $receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:receiver type:.Host + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun foo (p0: kotlin.String): kotlin.String declared in .test2' + CALL 'public final fun foo (vararg x: kotlin.String): kotlin.String declared in .Host' type=kotlin.String origin=null + $this: GET_VAR 'receiver: .Host declared in .test2.foo' type=.Host origin=ADAPTED_FUNCTION_REFERENCE + x: VARARG type=kotlin.Array varargElementType=kotlin.String + GET_VAR 'p0: kotlin.String declared in .test2.foo' type=kotlin.String origin=null + FUNCTION_REFERENCE 'local final fun foo (p0: kotlin.String): kotlin.String declared in .test2' type=kotlin.Function1 origin=ADAPTED_FUNCTION_REFERENCE reflectionTarget=public final fun foo (vararg x: kotlin.String): kotlin.String declared in .Host + $receiver: GET_OBJECT 'CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Host diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.kt.txt b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.kt.txt index 79c979ac54c..a24f57a40b1 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.kt.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.kt.txt @@ -66,8 +66,8 @@ fun testCoercionToUnit() { fun testImportedObjectMember(): String { return use(fn = { // BLOCK - local fun importedObjectMemberWithVarargs(p0: Int): String { - return importedObjectMemberWithVarargs(xs = [p0]) + local fun Host.importedObjectMemberWithVarargs(p0: Int): String { + return receiver.importedObjectMemberWithVarargs(xs = [p0]) } Host::importedObjectMemberWithVarargs diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.txt b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.txt index fcfdf40e20c..6665ea57a7b 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.txt @@ -105,11 +105,13 @@ FILE fqName: fileName:/withAdaptedArguments.kt RETURN type=kotlin.Nothing from='public final fun testImportedObjectMember (): kotlin.String declared in ' CALL 'public final fun use (fn: kotlin.Function1): kotlin.String declared in ' type=kotlin.String origin=null fn: BLOCK type=kotlin.Function1 origin=ADAPTED_FUNCTION_REFERENCE - FUN ADAPTER_FOR_CALLABLE_REFERENCE name:importedObjectMemberWithVarargs visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.String + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:importedObjectMemberWithVarargs visibility:local modality:FINAL <> ($receiver:.Host, p0:kotlin.Int) returnType:kotlin.String + $receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:receiver type:.Host VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int BLOCK_BODY RETURN type=kotlin.Nothing from='local final fun importedObjectMemberWithVarargs (p0: kotlin.Int): kotlin.String declared in .testImportedObjectMember' CALL 'public final fun importedObjectMemberWithVarargs (vararg xs: kotlin.Int): kotlin.String declared in .Host' type=kotlin.String origin=null + $this: GET_VAR 'receiver: .Host declared in .testImportedObjectMember.importedObjectMemberWithVarargs' type=.Host origin=ADAPTED_FUNCTION_REFERENCE xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int GET_VAR 'p0: kotlin.Int declared in .testImportedObjectMember.importedObjectMemberWithVarargs' type=kotlin.Int origin=null FUNCTION_REFERENCE 'local final fun importedObjectMemberWithVarargs (p0: kotlin.Int): kotlin.String declared in .testImportedObjectMember' type=kotlin.Function1 origin=ADAPTED_FUNCTION_REFERENCE reflectionTarget=public final fun importedObjectMemberWithVarargs (vararg xs: kotlin.Int): kotlin.String declared in .Host diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 30464e94d73..e9babf01b87 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -2522,6 +2522,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { @TestMetadata("compiler/testData/codegen/box/callableReference/adaptedReferences") @TestDataPath("$PROJECT_ROOT") public class AdaptedReferences { + @Test + @TestMetadata("adaptedVarargFunImportedFromObject.kt") + public void testAdaptedVarargFunImportedFromObject() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/adaptedVarargFunImportedFromObject.kt"); + } + @Test public void testAllFilesPresentInAdaptedReferences() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/adaptedReferences"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index a3329a7ce93..3a5647bd259 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -2522,6 +2522,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes @TestMetadata("compiler/testData/codegen/box/callableReference/adaptedReferences") @TestDataPath("$PROJECT_ROOT") public class AdaptedReferences { + @Test + @TestMetadata("adaptedVarargFunImportedFromObject.kt") + public void testAdaptedVarargFunImportedFromObject() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/adaptedVarargFunImportedFromObject.kt"); + } + @Test public void testAllFilesPresentInAdaptedReferences() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/adaptedReferences"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java index a0f02d9f4f9..243922a56de 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java @@ -1829,6 +1829,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest { runTest("compiler/testData/ir/irText/expressions/callableReferences/unboundMemberReferenceWithAdaptedArguments.kt"); } + @Test + @TestMetadata("varargFunImportedFromObject.kt") + public void testVarargFunImportedFromObject() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferences/varargFunImportedFromObject.kt"); + } + @Test @TestMetadata("withAdaptationForSam.kt") public void testWithAdaptationForSam() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index d0f36ee6b3d..d08046d590a 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -2218,6 +2218,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } + @TestMetadata("adaptedVarargFunImportedFromObject.kt") + public void testAdaptedVarargFunImportedFromObject() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/adaptedVarargFunImportedFromObject.kt"); + } + public void testAllFilesPresentInAdaptedReferences() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/adaptedReferences"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index d5a20bee4e0..62fbcac6447 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -1493,6 +1493,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath); } + @TestMetadata("adaptedVarargFunImportedFromObject.kt") + public void testAdaptedVarargFunImportedFromObject() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/adaptedVarargFunImportedFromObject.kt"); + } + public void testAllFilesPresentInAdaptedReferences() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/adaptedReferences"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true); } diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 8b486048aaf..d3b92601d73 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -1493,6 +1493,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); } + @TestMetadata("adaptedVarargFunImportedFromObject.kt") + public void testAdaptedVarargFunImportedFromObject() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/adaptedVarargFunImportedFromObject.kt"); + } + public void testAllFilesPresentInAdaptedReferences() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/adaptedReferences"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 6b4053e65b2..25a2cb619f7 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -1493,6 +1493,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath); } + @TestMetadata("adaptedVarargFunImportedFromObject.kt") + public void testAdaptedVarargFunImportedFromObject() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/adaptedVarargFunImportedFromObject.kt"); + } + public void testAllFilesPresentInAdaptedReferences() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/adaptedReferences"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); }