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 e9b4b0cbeb5..9bd182c39b3 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java @@ -1872,6 +1872,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/types/intersectionType3_OI.kt"); } + @TestMetadata("kt36143.kt") + public void testKt36143() throws Exception { + runTest("compiler/testData/ir/irText/types/kt36143.kt"); + } + @TestMetadata("localVariableOfIntersectionType_NI.kt") public void testLocalVariableOfIntersectionType_NI() throws Exception { runTest("compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.kt"); @@ -1892,6 +1897,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/types/smartCastOnReceiverOfGenericType.kt"); } + @TestMetadata("starProjection_OI.kt") + public void testStarProjection_OI() throws Exception { + runTest("compiler/testData/ir/irText/types/starProjection_OI.kt"); + } + @TestMetadata("compiler/testData/ir/irText/types/nullChecks") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt index e6476d8efd5..6dfc86a73dc 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt @@ -133,19 +133,26 @@ class TypeTranslator( return properlyApproximatedType } + private val isWithNewInference = languageVersionSettings.supportsFeature(LanguageFeature.NewInference) - private fun approximateByKotlinRules(ktType: KotlinType): KotlinType { - if (ktType.constructor.isDenotable) return ktType - - return if (languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) - typeApproximatorForNI.approximateDeclarationType( - ktType, - local = false, - languageVersionSettings = languageVersionSettings - ) - else - approximateCapturedTypes(ktType).upper - } + private fun approximateByKotlinRules(ktType: KotlinType): KotlinType = + if (isWithNewInference) { + if (ktType.constructor.isDenotable && ktType.arguments.isEmpty()) + ktType + else + typeApproximatorForNI.approximateDeclarationType( + ktType, + local = false, + languageVersionSettings = languageVersionSettings + ) + } else { + // Hack to preserve *-projections in arguments in OI. + // Expected to be removed as soon as OI is deprecated. + if (ktType.constructor.isDenotable) + ktType + else + approximateCapturedTypes(ktType).upper + } } diff --git a/compiler/testData/ir/irText/types/intersectionType1_NI.txt b/compiler/testData/ir/irText/types/intersectionType1_NI.txt index b6e21b83ef7..5193f4a299f 100644 --- a/compiler/testData/ir/irText/types/intersectionType1_NI.txt +++ b/compiler/testData/ir/irText/types/intersectionType1_NI.txt @@ -34,9 +34,9 @@ FILE fqName: fileName:/intersectionType1_NI.kt RETURN type=kotlin.Nothing from='public final fun foo (a: kotlin.Array<.In.foo>>, b: kotlin.Array<.In>): kotlin.Boolean declared in ' CALL 'public final fun ofType (y: kotlin.Any?): kotlin.Boolean [inline] declared in ' type=kotlin.Boolean origin=null : kotlin.Any? - $receiver: CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array [operator] declared in kotlin.Array' type=.In origin=GET_ARRAY_ELEMENT - $this: CALL 'public final fun select (x: S of .select, y: S of .select): S of .select declared in ' type=kotlin.Array.In> origin=null - : kotlin.Array.In> + $receiver: CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array [operator] declared in kotlin.Array' type=.In origin=GET_ARRAY_ELEMENT + $this: CALL 'public final fun select (x: S of .select, y: S of .select): S of .select declared in ' type=kotlin.Array.In> origin=null + : kotlin.Array.In> x: GET_VAR 'a: kotlin.Array<.In.foo>> declared in .foo' type=kotlin.Array<.In.foo>> origin=null y: GET_VAR 'b: kotlin.Array<.In> declared in .foo' type=kotlin.Array<.In> origin=null index: CONST Int type=kotlin.Int value=0 diff --git a/compiler/testData/ir/irText/types/intersectionType3_NI.txt b/compiler/testData/ir/irText/types/intersectionType3_NI.txt index 84d348df94a..1bac822f0b6 100644 --- a/compiler/testData/ir/irText/types/intersectionType3_NI.txt +++ b/compiler/testData/ir/irText/types/intersectionType3_NI.txt @@ -139,8 +139,8 @@ FILE fqName: fileName:/intersectionType3_NI.kt RETURN type=kotlin.Nothing from='public final fun testInIs1 (x: .In<.A>, y: .In<.B>): kotlin.Boolean declared in ' CALL 'public final fun isT (): kotlin.Boolean [inline] declared in ' type=kotlin.Boolean origin=null : kotlin.Any - $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In origin=null - : .In + $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In origin=null + : .In x: GET_VAR 'x: .In<.A> declared in .testInIs1' type=.In<.A> origin=null y: GET_VAR 'y: .In<.B> declared in .testInIs1' type=.In<.B> origin=null FUN name:testInIs2 visibility:public modality:FINAL <> (x:.In<.Z1>, y:.In<.Z2>) returnType:kotlin.Boolean @@ -150,8 +150,8 @@ FILE fqName: fileName:/intersectionType3_NI.kt RETURN type=kotlin.Nothing from='public final fun testInIs2 (x: .In<.Z1>, y: .In<.Z2>): kotlin.Boolean declared in ' CALL 'public final fun isT (): kotlin.Boolean [inline] declared in ' type=kotlin.Boolean origin=null : kotlin.Any - $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In origin=null - : .In + $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In origin=null + : .In x: GET_VAR 'x: .In<.Z1> declared in .testInIs2' type=.In<.Z1> origin=null y: GET_VAR 'y: .In<.Z2> declared in .testInIs2' type=.In<.Z2> origin=null FUN name:testInIs3 visibility:public modality:FINAL <> (x:.In<.A1>, y:.In<.A2>) returnType:kotlin.Boolean @@ -161,8 +161,8 @@ FILE fqName: fileName:/intersectionType3_NI.kt RETURN type=kotlin.Nothing from='public final fun testInIs3 (x: .In<.A1>, y: .In<.A2>): kotlin.Boolean declared in ' CALL 'public final fun isT (): kotlin.Boolean [inline] declared in ' type=kotlin.Boolean origin=null : .A - $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In<.A> origin=null - : .In<.A> + $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In origin=null + : .In x: GET_VAR 'x: .In<.A1> declared in .testInIs3' type=.In<.A1> origin=null y: GET_VAR 'y: .In<.A2> declared in .testInIs3' type=.In<.A2> origin=null FUN name:testInAs1 visibility:public modality:FINAL <> (x:.In<.A>, y:.In<.B>) returnType:kotlin.Unit @@ -172,8 +172,8 @@ FILE fqName: fileName:/intersectionType3_NI.kt RETURN type=kotlin.Nothing from='public final fun testInAs1 (x: .In<.A>, y: .In<.B>): kotlin.Unit declared in ' CALL 'public final fun asT (): kotlin.Unit [inline] declared in ' type=kotlin.Unit origin=null : kotlin.Any - $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In origin=null - : .In + $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In origin=null + : .In x: GET_VAR 'x: .In<.A> declared in .testInAs1' type=.In<.A> origin=null y: GET_VAR 'y: .In<.B> declared in .testInAs1' type=.In<.B> origin=null FUN name:testInAs2 visibility:public modality:FINAL <> (x:.In<.Z1>, y:.In<.Z2>) returnType:kotlin.Unit @@ -183,8 +183,8 @@ FILE fqName: fileName:/intersectionType3_NI.kt RETURN type=kotlin.Nothing from='public final fun testInAs2 (x: .In<.Z1>, y: .In<.Z2>): kotlin.Unit declared in ' CALL 'public final fun asT (): kotlin.Unit [inline] declared in ' type=kotlin.Unit origin=null : kotlin.Any - $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In origin=null - : .In + $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In origin=null + : .In x: GET_VAR 'x: .In<.Z1> declared in .testInAs2' type=.In<.Z1> origin=null y: GET_VAR 'y: .In<.Z2> declared in .testInAs2' type=.In<.Z2> origin=null FUN name:testInAs3 visibility:public modality:FINAL <> (x:.In<.A1>, y:.In<.A2>) returnType:kotlin.Unit @@ -194,7 +194,7 @@ FILE fqName: fileName:/intersectionType3_NI.kt RETURN type=kotlin.Nothing from='public final fun testInAs3 (x: .In<.A1>, y: .In<.A2>): kotlin.Unit declared in ' CALL 'public final fun asT (): kotlin.Unit [inline] declared in ' type=kotlin.Unit origin=null : .A - $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In<.A> origin=null - : .In<.A> + $receiver: CALL 'public final fun sel (x: S of .sel, y: S of .sel): S of .sel declared in ' type=.In origin=null + : .In x: GET_VAR 'x: .In<.A1> declared in .testInAs3' type=.In<.A1> origin=null y: GET_VAR 'y: .In<.A2> declared in .testInAs3' type=.In<.A2> origin=null diff --git a/compiler/testData/ir/irText/types/kt36143.fir.txt b/compiler/testData/ir/irText/types/kt36143.fir.txt new file mode 100644 index 00000000000..7ad9d3cc532 --- /dev/null +++ b/compiler/testData/ir/irText/types/kt36143.fir.txt @@ -0,0 +1,7 @@ +FILE fqName: fileName:/kt36143.kt + FUN name:test visibility:public modality:FINAL <> ($receiver:kotlin.Array) returnType:kotlin.Int + $receiver: VALUE_PARAMETER name: type:kotlin.Array + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test (): kotlin.Int declared in ' + CALL 'public final fun (): kotlin.Int declared in kotlin.Array' type=kotlin.Int origin=null + $this: GET_VAR ': kotlin.Array declared in .test' type=kotlin.Array origin=null diff --git a/compiler/testData/ir/irText/types/kt36143.kt b/compiler/testData/ir/irText/types/kt36143.kt new file mode 100644 index 00000000000..db18604b829 --- /dev/null +++ b/compiler/testData/ir/irText/types/kt36143.kt @@ -0,0 +1 @@ +fun Array.test() = size \ No newline at end of file diff --git a/compiler/testData/ir/irText/types/kt36143.txt b/compiler/testData/ir/irText/types/kt36143.txt new file mode 100644 index 00000000000..8374d5b8af3 --- /dev/null +++ b/compiler/testData/ir/irText/types/kt36143.txt @@ -0,0 +1,7 @@ +FILE fqName: fileName:/kt36143.kt + FUN name:test visibility:public modality:FINAL <> ($receiver:kotlin.Array) returnType:kotlin.Int + $receiver: VALUE_PARAMETER name: type:kotlin.Array + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test (): kotlin.Int declared in ' + CALL 'public final fun (): kotlin.Int declared in kotlin.Array' type=kotlin.Int origin=GET_PROPERTY + $this: GET_VAR ': kotlin.Array declared in .test' type=kotlin.Array origin=null diff --git a/compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.txt b/compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.txt index a7886b0339d..067527ec2f1 100644 --- a/compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.txt +++ b/compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.txt @@ -96,21 +96,21 @@ FILE fqName: fileName:/localVariableOfIntersectionType_NI.kt BLOCK_BODY CALL 'public abstract fun foo (): kotlin.Unit declared in .IA' type=kotlin.Unit origin=null $this: CALL 'public abstract fun (): T of .Inv declared in .Inv' type=kotlin.Any origin=GET_PROPERTY - $this: CALL 'public abstract fun create (x: .In.Z.create>, y: .In.Z.create>): .Inv.Z.create> declared in .Z' type=.Inv origin=null + $this: CALL 'public abstract fun create (x: .In.Z.create>, y: .In.Z.create>): .Inv.Z.create> declared in .Z' type=.Inv origin=null : kotlin.Any $this: GET_VAR 'z: .Z declared in .test' type=.Z origin=null x: GET_VAR 'a: .In<.IA> declared in .test' type=.In<.IA> origin=null y: GET_VAR 'b: .In<.IB> declared in .test' type=.In<.IB> origin=null CALL 'public abstract fun bar (): kotlin.Unit declared in .IB' type=kotlin.Unit origin=null $this: CALL 'public abstract fun (): T of .Inv declared in .Inv' type=kotlin.Any origin=GET_PROPERTY - $this: CALL 'public abstract fun create (x: .In.Z.create>, y: .In.Z.create>): .Inv.Z.create> declared in .Z' type=.Inv origin=null + $this: CALL 'public abstract fun create (x: .In.Z.create>, y: .In.Z.create>): .Inv.Z.create> declared in .Z' type=.Inv origin=null : kotlin.Any $this: GET_VAR 'z: .Z declared in .test' type=.Z origin=null x: GET_VAR 'a: .In<.IA> declared in .test' type=.In<.IA> origin=null y: GET_VAR 'b: .In<.IB> declared in .test' type=.In<.IB> origin=null VAR name:t type:kotlin.Any [val] CALL 'public abstract fun (): T of .Inv declared in .Inv' type=kotlin.Any origin=GET_PROPERTY - $this: CALL 'public abstract fun create (x: .In.Z.create>, y: .In.Z.create>): .Inv.Z.create> declared in .Z' type=.Inv origin=null + $this: CALL 'public abstract fun create (x: .In.Z.create>, y: .In.Z.create>): .Inv.Z.create> declared in .Z' type=.Inv origin=null : kotlin.Any $this: GET_VAR 'z: .Z declared in .test' type=.Z origin=null x: GET_VAR 'a: .In<.IA> declared in .test' type=.In<.IA> origin=null diff --git a/compiler/testData/ir/irText/types/starProjection_OI.kt b/compiler/testData/ir/irText/types/starProjection_OI.kt new file mode 100644 index 00000000000..e4da55fba7a --- /dev/null +++ b/compiler/testData/ir/irText/types/starProjection_OI.kt @@ -0,0 +1,8 @@ +// !LANGUAGE: -NewInference +// FIR_IDENTICAL + +interface Continuation + +abstract class C { + abstract fun dispatchResumeWithException(exception: Throwable, continuation: Continuation<*>): Boolean +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/types/starProjection_OI.txt b/compiler/testData/ir/irText/types/starProjection_OI.txt new file mode 100644 index 00000000000..14bf75ebab5 --- /dev/null +++ b/compiler/testData/ir/irText/types/starProjection_OI.txt @@ -0,0 +1,40 @@ +FILE fqName: fileName:/starProjection_OI.kt + CLASS INTERFACE name:Continuation modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Continuation.Continuation> + TYPE_PARAMETER name:T index:0 variance:in superTypes:[kotlin.Any?] + 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 + CLASS CLASS name:C modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.C + CONSTRUCTOR visibility:public <> () returnType:.C [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:ABSTRACT visibility:public superTypes:[kotlin.Any]' + FUN name:dispatchResumeWithException visibility:public modality:ABSTRACT <> ($this:.C, exception:kotlin.Throwable, continuation:.Continuation<*>) returnType:kotlin.Boolean + $this: VALUE_PARAMETER name: type:.C + VALUE_PARAMETER name:exception index:0 type:kotlin.Throwable + VALUE_PARAMETER name:continuation index:1 type:.Continuation<*> + 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 diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index c8b6ad6e7ae..7d97f7bf4b5 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -1871,6 +1871,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/types/intersectionType3_OI.kt"); } + @TestMetadata("kt36143.kt") + public void testKt36143() throws Exception { + runTest("compiler/testData/ir/irText/types/kt36143.kt"); + } + @TestMetadata("localVariableOfIntersectionType_NI.kt") public void testLocalVariableOfIntersectionType_NI() throws Exception { runTest("compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.kt"); @@ -1891,6 +1896,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/types/smartCastOnReceiverOfGenericType.kt"); } + @TestMetadata("starProjection_OI.kt") + public void testStarProjection_OI() throws Exception { + runTest("compiler/testData/ir/irText/types/starProjection_OI.kt"); + } + @TestMetadata("compiler/testData/ir/irText/types/nullChecks") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)