Don't approximate types arguments isolated from top-level type
#KT-36143 Fixed
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 e9b4b0c..8baa2df 100644
--- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java
+++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java
@@ -1822,6 +1822,11 @@
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/irText/types"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
+ @TestMetadata("approximationOfInvariatOutProjectedTypes.kt")
+ public void testApproximationOfInvariatOutProjectedTypes() throws Exception {
+ runTest("compiler/testData/ir/irText/types/approximationOfInvariatOutProjectedTypes.kt");
+ }
+
@TestMetadata("asOnPlatformType.kt")
public void testAsOnPlatformType() throws Exception {
runTest("compiler/testData/ir/irText/types/asOnPlatformType.kt");
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 e6476d8..45864de 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
@@ -135,7 +135,7 @@
private fun approximateByKotlinRules(ktType: KotlinType): KotlinType {
- if (ktType.constructor.isDenotable) return ktType
+ if (ktType.constructor.isDenotable && ktType.arguments.isEmpty()) return ktType
return if (languageVersionSettings.supportsFeature(LanguageFeature.NewInference))
typeApproximatorForNI.approximateDeclarationType(
diff --git a/compiler/testData/ir/irText/types/approximationOfInvariatOutProjectedTypes.kt b/compiler/testData/ir/irText/types/approximationOfInvariatOutProjectedTypes.kt
new file mode 100644
index 0000000..db18604
--- /dev/null
+++ b/compiler/testData/ir/irText/types/approximationOfInvariatOutProjectedTypes.kt
@@ -0,0 +1 @@
+fun Array<out String>.test() = size
\ No newline at end of file
diff --git a/compiler/testData/ir/irText/types/approximationOfInvariatOutProjectedTypes.txt b/compiler/testData/ir/irText/types/approximationOfInvariatOutProjectedTypes.txt
new file mode 100644
index 0000000..7d43d13
--- /dev/null
+++ b/compiler/testData/ir/irText/types/approximationOfInvariatOutProjectedTypes.txt
@@ -0,0 +1,7 @@
+FILE fqName:<root> fileName:/approximationOfInvariatOutProjectedTypes.kt
+ FUN name:test visibility:public modality:FINAL <> ($receiver:kotlin.Array<out kotlin.String>) returnType:kotlin.Int
+ $receiver: VALUE_PARAMETER name:<this> type:kotlin.Array<out kotlin.String>
+ BLOCK_BODY
+ RETURN type=kotlin.Nothing from='public final fun test (): kotlin.Int declared in <root>'
+ CALL 'public final fun <get-size> (): kotlin.Int declared in kotlin.Array' type=kotlin.Int origin=GET_PROPERTY
+ $this: GET_VAR '<this>: kotlin.Array<out kotlin.String> declared in <root>.test' type=kotlin.Array<out kotlin.String> origin=null
diff --git a/compiler/testData/ir/irText/types/intersectionType1_NI.txt b/compiler/testData/ir/irText/types/intersectionType1_NI.txt
index b6e21b8..5193f4a 100644
--- a/compiler/testData/ir/irText/types/intersectionType1_NI.txt
+++ b/compiler/testData/ir/irText/types/intersectionType1_NI.txt
@@ -34,9 +34,9 @@
RETURN type=kotlin.Nothing from='public final fun foo <T> (a: kotlin.Array<<root>.In<T of <root>.foo>>, b: kotlin.Array<<root>.In<kotlin.String>>): kotlin.Boolean declared in <root>'
CALL 'public final fun ofType <K> (y: kotlin.Any?): kotlin.Boolean [inline] declared in <root>' type=kotlin.Boolean origin=null
<K>: kotlin.Any?
- $receiver: CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array [operator] declared in kotlin.Array' type=<root>.In<kotlin.Any?> origin=GET_ARRAY_ELEMENT
- $this: CALL 'public final fun select <S> (x: S of <root>.select, y: S of <root>.select): S of <root>.select declared in <root>' type=kotlin.Array<out <root>.In<kotlin.Any?>> origin=null
- <S>: kotlin.Array<out <root>.In<kotlin.Any?>>
+ $receiver: CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array [operator] declared in kotlin.Array' type=<root>.In<kotlin.Nothing> origin=GET_ARRAY_ELEMENT
+ $this: CALL 'public final fun select <S> (x: S of <root>.select, y: S of <root>.select): S of <root>.select declared in <root>' type=kotlin.Array<out <root>.In<kotlin.Nothing>> origin=null
+ <S>: kotlin.Array<out <root>.In<kotlin.Nothing>>
x: GET_VAR 'a: kotlin.Array<<root>.In<T of <root>.foo>> declared in <root>.foo' type=kotlin.Array<<root>.In<T of <root>.foo>> origin=null
y: GET_VAR 'b: kotlin.Array<<root>.In<kotlin.String>> declared in <root>.foo' type=kotlin.Array<<root>.In<kotlin.String>> 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 84d348d..1bac822 100644
--- a/compiler/testData/ir/irText/types/intersectionType3_NI.txt
+++ b/compiler/testData/ir/irText/types/intersectionType3_NI.txt
@@ -139,8 +139,8 @@
RETURN type=kotlin.Nothing from='public final fun testInIs1 (x: <root>.In<<root>.A>, y: <root>.In<<root>.B>): kotlin.Boolean declared in <root>'
CALL 'public final fun isT <T> (): kotlin.Boolean [inline] declared in <root>' type=kotlin.Boolean origin=null
<T>: kotlin.Any
- $receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<kotlin.Any> origin=null
- <S>: <root>.In<kotlin.Any>
+ $receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<kotlin.Nothing> origin=null
+ <S>: <root>.In<kotlin.Nothing>
x: GET_VAR 'x: <root>.In<<root>.A> declared in <root>.testInIs1' type=<root>.In<<root>.A> origin=null
y: GET_VAR 'y: <root>.In<<root>.B> declared in <root>.testInIs1' type=<root>.In<<root>.B> origin=null
FUN name:testInIs2 visibility:public modality:FINAL <> (x:<root>.In<<root>.Z1>, y:<root>.In<<root>.Z2>) returnType:kotlin.Boolean
@@ -150,8 +150,8 @@
RETURN type=kotlin.Nothing from='public final fun testInIs2 (x: <root>.In<<root>.Z1>, y: <root>.In<<root>.Z2>): kotlin.Boolean declared in <root>'
CALL 'public final fun isT <T> (): kotlin.Boolean [inline] declared in <root>' type=kotlin.Boolean origin=null
<T>: kotlin.Any
- $receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<kotlin.Any> origin=null
- <S>: <root>.In<kotlin.Any>
+ $receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<kotlin.Nothing> origin=null
+ <S>: <root>.In<kotlin.Nothing>
x: GET_VAR 'x: <root>.In<<root>.Z1> declared in <root>.testInIs2' type=<root>.In<<root>.Z1> origin=null
y: GET_VAR 'y: <root>.In<<root>.Z2> declared in <root>.testInIs2' type=<root>.In<<root>.Z2> origin=null
FUN name:testInIs3 visibility:public modality:FINAL <> (x:<root>.In<<root>.A1>, y:<root>.In<<root>.A2>) returnType:kotlin.Boolean
@@ -161,8 +161,8 @@
RETURN type=kotlin.Nothing from='public final fun testInIs3 (x: <root>.In<<root>.A1>, y: <root>.In<<root>.A2>): kotlin.Boolean declared in <root>'
CALL 'public final fun isT <T> (): kotlin.Boolean [inline] declared in <root>' type=kotlin.Boolean origin=null
<T>: <root>.A
- $receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<<root>.A> origin=null
- <S>: <root>.In<<root>.A>
+ $receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<kotlin.Nothing> origin=null
+ <S>: <root>.In<kotlin.Nothing>
x: GET_VAR 'x: <root>.In<<root>.A1> declared in <root>.testInIs3' type=<root>.In<<root>.A1> origin=null
y: GET_VAR 'y: <root>.In<<root>.A2> declared in <root>.testInIs3' type=<root>.In<<root>.A2> origin=null
FUN name:testInAs1 visibility:public modality:FINAL <> (x:<root>.In<<root>.A>, y:<root>.In<<root>.B>) returnType:kotlin.Unit
@@ -172,8 +172,8 @@
RETURN type=kotlin.Nothing from='public final fun testInAs1 (x: <root>.In<<root>.A>, y: <root>.In<<root>.B>): kotlin.Unit declared in <root>'
CALL 'public final fun asT <T> (): kotlin.Unit [inline] declared in <root>' type=kotlin.Unit origin=null
<T>: kotlin.Any
- $receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<kotlin.Any> origin=null
- <S>: <root>.In<kotlin.Any>
+ $receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<kotlin.Nothing> origin=null
+ <S>: <root>.In<kotlin.Nothing>
x: GET_VAR 'x: <root>.In<<root>.A> declared in <root>.testInAs1' type=<root>.In<<root>.A> origin=null
y: GET_VAR 'y: <root>.In<<root>.B> declared in <root>.testInAs1' type=<root>.In<<root>.B> origin=null
FUN name:testInAs2 visibility:public modality:FINAL <> (x:<root>.In<<root>.Z1>, y:<root>.In<<root>.Z2>) returnType:kotlin.Unit
@@ -183,8 +183,8 @@
RETURN type=kotlin.Nothing from='public final fun testInAs2 (x: <root>.In<<root>.Z1>, y: <root>.In<<root>.Z2>): kotlin.Unit declared in <root>'
CALL 'public final fun asT <T> (): kotlin.Unit [inline] declared in <root>' type=kotlin.Unit origin=null
<T>: kotlin.Any
- $receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<kotlin.Any> origin=null
- <S>: <root>.In<kotlin.Any>
+ $receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<kotlin.Nothing> origin=null
+ <S>: <root>.In<kotlin.Nothing>
x: GET_VAR 'x: <root>.In<<root>.Z1> declared in <root>.testInAs2' type=<root>.In<<root>.Z1> origin=null
y: GET_VAR 'y: <root>.In<<root>.Z2> declared in <root>.testInAs2' type=<root>.In<<root>.Z2> origin=null
FUN name:testInAs3 visibility:public modality:FINAL <> (x:<root>.In<<root>.A1>, y:<root>.In<<root>.A2>) returnType:kotlin.Unit
@@ -194,7 +194,7 @@
RETURN type=kotlin.Nothing from='public final fun testInAs3 (x: <root>.In<<root>.A1>, y: <root>.In<<root>.A2>): kotlin.Unit declared in <root>'
CALL 'public final fun asT <T> (): kotlin.Unit [inline] declared in <root>' type=kotlin.Unit origin=null
<T>: <root>.A
- $receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<<root>.A> origin=null
- <S>: <root>.In<<root>.A>
+ $receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<kotlin.Nothing> origin=null
+ <S>: <root>.In<kotlin.Nothing>
x: GET_VAR 'x: <root>.In<<root>.A1> declared in <root>.testInAs3' type=<root>.In<<root>.A1> origin=null
y: GET_VAR 'y: <root>.In<<root>.A2> declared in <root>.testInAs3' type=<root>.In<<root>.A2> origin=null
diff --git a/compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.txt b/compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.txt
index a7886b0..067527e 100644
--- a/compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.txt
+++ b/compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.txt
@@ -96,21 +96,21 @@
BLOCK_BODY
CALL 'public abstract fun foo (): kotlin.Unit declared in <root>.IA' type=kotlin.Unit origin=null
$this: CALL 'public abstract fun <get-t> (): T of <root>.Inv declared in <root>.Inv' type=kotlin.Any origin=GET_PROPERTY
- $this: CALL 'public abstract fun create <T> (x: <root>.In<T of <root>.Z.create>, y: <root>.In<T of <root>.Z.create>): <root>.Inv<T of <root>.Z.create> declared in <root>.Z' type=<root>.Inv<kotlin.Any> origin=null
+ $this: CALL 'public abstract fun create <T> (x: <root>.In<T of <root>.Z.create>, y: <root>.In<T of <root>.Z.create>): <root>.Inv<T of <root>.Z.create> declared in <root>.Z' type=<root>.Inv<out kotlin.Any> origin=null
<T>: kotlin.Any
$this: GET_VAR 'z: <root>.Z declared in <root>.test' type=<root>.Z origin=null
x: GET_VAR 'a: <root>.In<<root>.IA> declared in <root>.test' type=<root>.In<<root>.IA> origin=null
y: GET_VAR 'b: <root>.In<<root>.IB> declared in <root>.test' type=<root>.In<<root>.IB> origin=null
CALL 'public abstract fun bar (): kotlin.Unit declared in <root>.IB' type=kotlin.Unit origin=null
$this: CALL 'public abstract fun <get-t> (): T of <root>.Inv declared in <root>.Inv' type=kotlin.Any origin=GET_PROPERTY
- $this: CALL 'public abstract fun create <T> (x: <root>.In<T of <root>.Z.create>, y: <root>.In<T of <root>.Z.create>): <root>.Inv<T of <root>.Z.create> declared in <root>.Z' type=<root>.Inv<kotlin.Any> origin=null
+ $this: CALL 'public abstract fun create <T> (x: <root>.In<T of <root>.Z.create>, y: <root>.In<T of <root>.Z.create>): <root>.Inv<T of <root>.Z.create> declared in <root>.Z' type=<root>.Inv<out kotlin.Any> origin=null
<T>: kotlin.Any
$this: GET_VAR 'z: <root>.Z declared in <root>.test' type=<root>.Z origin=null
x: GET_VAR 'a: <root>.In<<root>.IA> declared in <root>.test' type=<root>.In<<root>.IA> origin=null
y: GET_VAR 'b: <root>.In<<root>.IB> declared in <root>.test' type=<root>.In<<root>.IB> origin=null
VAR name:t type:kotlin.Any [val]
CALL 'public abstract fun <get-t> (): T of <root>.Inv declared in <root>.Inv' type=kotlin.Any origin=GET_PROPERTY
- $this: CALL 'public abstract fun create <T> (x: <root>.In<T of <root>.Z.create>, y: <root>.In<T of <root>.Z.create>): <root>.Inv<T of <root>.Z.create> declared in <root>.Z' type=<root>.Inv<kotlin.Any> origin=null
+ $this: CALL 'public abstract fun create <T> (x: <root>.In<T of <root>.Z.create>, y: <root>.In<T of <root>.Z.create>): <root>.Inv<T of <root>.Z.create> declared in <root>.Z' type=<root>.Inv<out kotlin.Any> origin=null
<T>: kotlin.Any
$this: GET_VAR 'z: <root>.Z declared in <root>.test' type=<root>.Z origin=null
x: GET_VAR 'a: <root>.In<<root>.IA> declared in <root>.test' type=<root>.In<<root>.IA> origin=null
diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java
index c8b6ad6..6ca5f0f 100644
--- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java
+++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java
@@ -1821,6 +1821,11 @@
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/irText/types"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
+ @TestMetadata("approximationOfInvariatOutProjectedTypes.kt")
+ public void testApproximationOfInvariatOutProjectedTypes() throws Exception {
+ runTest("compiler/testData/ir/irText/types/approximationOfInvariatOutProjectedTypes.kt");
+ }
+
@TestMetadata("asOnPlatformType.kt")
public void testAsOnPlatformType() throws Exception {
runTest("compiler/testData/ir/irText/types/asOnPlatformType.kt");