[FIR] support flexible types in ConeKotlinType#independentInstance

^KT-60580 Fixed
This commit is contained in:
Dmitrii Gridin
2023-07-20 16:16:48 +02:00
committed by Space Team
parent dc56c5cf9e
commit 8820867341
7 changed files with 70 additions and 1 deletions
@@ -20156,6 +20156,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/j+k/kt36856.kt");
}
@Test
@TestMetadata("kt60580.kt")
public void testKt60580() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/kt60580.kt");
}
@Test
@TestMetadata("kt6720_abstractProperty.kt")
public void testKt6720_abstractProperty() throws Exception {
@@ -20156,6 +20156,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/j+k/kt36856.kt");
}
@Test
@TestMetadata("kt60580.kt")
public void testKt60580() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/kt60580.kt");
}
@Test
@TestMetadata("kt6720_abstractProperty.kt")
public void testKt6720_abstractProperty() throws Exception {
@@ -20156,6 +20156,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/j+k/kt36856.kt");
}
@Test
@TestMetadata("kt60580.kt")
public void testKt60580() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/kt60580.kt");
}
@Test
@TestMetadata("kt6720_abstractProperty.kt")
public void testKt6720_abstractProperty() throws Exception {
@@ -20162,6 +20162,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/j+k/kt36856.kt");
}
@Test
@TestMetadata("kt60580.kt")
public void testKt60580() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/kt60580.kt");
}
@Test
@TestMetadata("kt6720_abstractProperty.kt")
public void testKt6720_abstractProperty() throws Exception {
@@ -136,7 +136,22 @@ fun ConeDynamicType.Companion.create(session: FirSession): ConeDynamicType =
*
* @see CustomAnnotationTypeAttribute.independentInstance
*/
fun ConeKotlinType.independentInstance(): ConeKotlinType = instanceWithIndependentArguments().instanceWithIndependentAnnotations()
@OptIn(DynamicTypeConstructor::class)
fun ConeKotlinType.independentInstance(): ConeKotlinType = if (this is ConeFlexibleType) {
val newLowerBound = lowerBound.independentInstance() as ConeSimpleKotlinType
val newUpperBound = upperBound.independentInstance() as ConeSimpleKotlinType
if (newLowerBound !== lowerBound || newUpperBound !== upperBound) {
when (this) {
is ConeRawType -> ConeRawType.create(newLowerBound, newUpperBound)
is ConeDynamicType -> ConeDynamicType(newLowerBound, newUpperBound)
else -> ConeFlexibleType(newLowerBound, newUpperBound)
}
} else {
this
}
} else {
instanceWithIndependentArguments().instanceWithIndependentAnnotations()
}
private fun ConeKotlinType.instanceWithIndependentArguments(): ConeKotlinType {
val typeProjections = typeArguments
+24
View File
@@ -0,0 +1,24 @@
// FIR_IDENTICAL
// FILE: usage.kt
@Target(AnnotationTarget.TYPE)
annotation class Anno
data class P<T1, T2>(val t1: T1, val t2: T2)
fun foo(m: Manager<P<Int, @Anno String>>) {
m.action {}
}
// FILE: Manager.java
import org.jetbrains.annotations.NotNull;
public interface Manager<T> {
@NotNull
Manager<T> action(@NotNull Consumer<? super T> handler);
}
// FILE: Consumer.java
@FunctionalInterface
public interface Consumer<T> {
void accept(T t);
}
@@ -20162,6 +20162,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/j+k/kt36856.kt");
}
@Test
@TestMetadata("kt60580.kt")
public void testKt60580() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/kt60580.kt");
}
@Test
@TestMetadata("kt6720_abstractProperty.kt")
public void testKt6720_abstractProperty() throws Exception {