diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java index b1bf3107ddd..17eae18577f 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java @@ -1847,6 +1847,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/types/genericPropertyReferenceType.kt"); } + @TestMetadata("inStarProjectionInReceiverType.kt") + public void testInStarProjectionInReceiverType() throws Exception { + runTest("compiler/testData/ir/irText/types/inStarProjectionInReceiverType.kt"); + } + @TestMetadata("intersectionType1_NI.kt") public void testIntersectionType1_NI() throws Exception { runTest("compiler/testData/ir/irText/types/intersectionType1_NI.kt"); diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt index fa0eda92b5a..ecfe3a3b9d4 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt @@ -56,7 +56,13 @@ fun StatementGenerator.generateReceiver(ktDefaultElement: KtElement, receiver: R generateReceiver(ktDefaultElement.startOffsetSkippingComments, ktDefaultElement.endOffset, receiver) fun StatementGenerator.generateReceiver(defaultStartOffset: Int, defaultEndOffset: Int, receiver: ReceiverValue): IntermediateValue { - val irReceiverType = receiver.type.toIrType() + val irReceiverType = + when (receiver) { + is ExtensionReceiver -> + receiver.declarationDescriptor.extensionReceiverParameter!!.type.toIrType() + else -> + receiver.type.toIrType() + } if (receiver is TransientReceiver) return TransientReceiverValue(irReceiverType) diff --git a/compiler/testData/ir/irText/types/inStarProjectionInReceiverType.fir.txt b/compiler/testData/ir/irText/types/inStarProjectionInReceiverType.fir.txt new file mode 100644 index 00000000000..0de41404db1 --- /dev/null +++ b/compiler/testData/ir/irText/types/inStarProjectionInReceiverType.fir.txt @@ -0,0 +1,45 @@ +FILE fqName: fileName:/inStarProjectionInReceiverType.kt + CLASS INTERFACE name:Foo modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Foo.Foo> + TYPE_PARAMETER name:T index:0 variance:in superTypes:[kotlin.Any?] + PROPERTY name:x visibility:public modality:ABSTRACT [val] + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:ABSTRACT <> ($this:.Foo.Foo>) returnType:kotlin.Int + correspondingProperty: PROPERTY name:x visibility:public modality:ABSTRACT [val] + $this: VALUE_PARAMETER name: type:.Foo.Foo> + FUN name:foo visibility:public modality:ABSTRACT <> ($this:.Foo.Foo>, x:T of .Foo) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.Foo.Foo> + VALUE_PARAMETER name:x index:0 type:T of .Foo + 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:testReceiver visibility:public modality:FINAL <> ($receiver:.Foo<*>) returnType:kotlin.Int + $receiver: VALUE_PARAMETER name: type:.Foo<*> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testReceiver (): kotlin.Int declared in ' + CALL 'public abstract fun (): kotlin.Int declared in .Foo' type=kotlin.Int origin=GET_PROPERTY + $this: GET_VAR ': .Foo<*> declared in .testReceiver' type=.Foo<*> origin=null + FUN name:testSmartCastOnExtensionReceiver visibility:public modality:FINAL <> ($receiver:.Foo<*>) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name: type:.Foo<*> + BLOCK_BODY + TYPE_OP type=.Foo origin=CAST typeOperand=.Foo + GET_VAR ': .Foo<*> declared in .testSmartCastOnExtensionReceiver' type=.Foo<*> origin=null + CALL 'public abstract fun foo (x: T of .Foo): kotlin.Unit declared in .Foo' type=kotlin.Unit origin=null + $this: TYPE_OP type=.Foo origin=IMPLICIT_CAST typeOperand=.Foo + GET_VAR ': .Foo<*> declared in .testSmartCastOnExtensionReceiver' type=.Foo<*> origin=null + x: CONST String type=kotlin.String value="string" + FUN name:testValueParameter visibility:public modality:FINAL <> (vp:.Foo<*>) returnType:kotlin.Int + VALUE_PARAMETER name:vp index:0 type:.Foo<*> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testValueParameter (vp: .Foo<*>): kotlin.Int declared in ' + CALL 'public abstract fun (): kotlin.Int declared in .Foo' type=kotlin.Int origin=GET_PROPERTY + $this: GET_VAR 'vp: .Foo<*> declared in .testValueParameter' type=.Foo<*> origin=null diff --git a/compiler/testData/ir/irText/types/inStarProjectionInReceiverType.kt b/compiler/testData/ir/irText/types/inStarProjectionInReceiverType.kt new file mode 100644 index 00000000000..0f018d9948a --- /dev/null +++ b/compiler/testData/ir/irText/types/inStarProjectionInReceiverType.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +NewInference + +interface Foo { + val x: Int + fun foo(x: T) +} + +fun Foo<*>.testReceiver() = x + +fun Foo<*>.testSmartCastOnExtensionReceiver() { + this as Foo + foo("string") +} + +fun testValueParameter(vp: Foo<*>) = vp.x \ No newline at end of file diff --git a/compiler/testData/ir/irText/types/inStarProjectionInReceiverType.txt b/compiler/testData/ir/irText/types/inStarProjectionInReceiverType.txt new file mode 100644 index 00000000000..3ea2b3c9cea --- /dev/null +++ b/compiler/testData/ir/irText/types/inStarProjectionInReceiverType.txt @@ -0,0 +1,46 @@ +FILE fqName: fileName:/inStarProjectionInReceiverType.kt + CLASS INTERFACE name:Foo modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Foo.Foo> + TYPE_PARAMETER name:T index:0 variance:in superTypes:[kotlin.Any?] + PROPERTY name:x visibility:public modality:ABSTRACT [val] + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:ABSTRACT <> ($this:.Foo.Foo>) returnType:kotlin.Int + correspondingProperty: PROPERTY name:x visibility:public modality:ABSTRACT [val] + $this: VALUE_PARAMETER name: type:.Foo.Foo> + FUN name:foo visibility:public modality:ABSTRACT <> ($this:.Foo.Foo>, x:T of .Foo) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.Foo.Foo> + VALUE_PARAMETER name:x index:0 type:T of .Foo + 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:testReceiver visibility:public modality:FINAL <> ($receiver:.Foo<*>) returnType:kotlin.Int + $receiver: VALUE_PARAMETER name: type:.Foo<*> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testReceiver (): kotlin.Int declared in ' + CALL 'public abstract fun (): kotlin.Int declared in .Foo' type=kotlin.Int origin=GET_PROPERTY + $this: GET_VAR ': .Foo<*> declared in .testReceiver' type=.Foo<*> origin=null + FUN name:testSmartCastOnExtensionReceiver visibility:public modality:FINAL <> ($receiver:.Foo<*>) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name: type:.Foo<*> + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + TYPE_OP type=.Foo origin=CAST typeOperand=.Foo + GET_VAR ': .Foo<*> declared in .testSmartCastOnExtensionReceiver' type=.Foo<*> origin=null + CALL 'public abstract fun foo (x: T of .Foo): kotlin.Unit declared in .Foo' type=kotlin.Unit origin=null + $this: TYPE_OP type=.Foo origin=IMPLICIT_CAST typeOperand=.Foo + GET_VAR ': .Foo<*> declared in .testSmartCastOnExtensionReceiver' type=.Foo<*> origin=null + x: CONST String type=kotlin.String value="string" + FUN name:testValueParameter visibility:public modality:FINAL <> (vp:.Foo<*>) returnType:kotlin.Int + VALUE_PARAMETER name:vp index:0 type:.Foo<*> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testValueParameter (vp: .Foo<*>): kotlin.Int declared in ' + CALL 'public abstract fun (): kotlin.Int declared in .Foo' type=kotlin.Int origin=GET_PROPERTY + $this: GET_VAR 'vp: .Foo<*> declared in .testValueParameter' type=.Foo<*> origin=null diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 99d33b339e0..706f43e48d0 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -1846,6 +1846,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/types/genericPropertyReferenceType.kt"); } + @TestMetadata("inStarProjectionInReceiverType.kt") + public void testInStarProjectionInReceiverType() throws Exception { + runTest("compiler/testData/ir/irText/types/inStarProjectionInReceiverType.kt"); + } + @TestMetadata("intersectionType1_NI.kt") public void testIntersectionType1_NI() throws Exception { runTest("compiler/testData/ir/irText/types/intersectionType1_NI.kt");