K2: Fix deserialization of flexible type based on type parameter

It's anyway safe to use avoidComprehensiveCheck = true because
during deserialization we're sure that we need DNN type because
it's been serialized as such.
This commit is contained in:
Denis.Zharkov
2022-11-23 17:35:23 +01:00
committed by Space Team
parent ff340505ec
commit f7d8fd54ca
7 changed files with 55 additions and 2 deletions
@@ -34,7 +34,6 @@ import org.jetbrains.kotlin.serialization.deserialization.ProtoEnumFlags
import org.jetbrains.kotlin.serialization.deserialization.getClassId
import org.jetbrains.kotlin.serialization.deserialization.getName
import org.jetbrains.kotlin.types.Variance
import java.util.*
class FirTypeDeserializer(
val moduleData: FirModuleData,
@@ -164,7 +163,7 @@ class FirTypeDeserializer(
if (constructor is ConeTypeParameterLookupTag) {
return ConeTypeParameterTypeImpl(constructor, isNullable = proto.nullable).let {
if (Flags.DEFINITELY_NOT_NULL_TYPE.get(proto.flags))
ConeDefinitelyNotNullType.create(it, moduleData.session.typeContext) ?: it
ConeDefinitelyNotNullType.create(it, moduleData.session.typeContext, avoidComprehensiveCheck = true) ?: it
else
it
}
@@ -7688,6 +7688,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/IrConstAcceptMultiModule.kt");
}
@Test
@TestMetadata("javaTypeParameterBy.kt")
public void testJavaTypeParameterBy() throws Exception {
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/javaTypeParameterBy.kt");
}
@Test
@TestMetadata("LibraryProperty.kt")
public void testLibraryProperty() throws Exception {
@@ -0,0 +1,24 @@
// TARGET_BACKEND: JVM
// WITH_STDLIB
// MODULE: lib
// FILE: JavaInterface.java
public interface JavaInterface {
<K extends Comparable<K>> K foo();
}
// FILE: A.kt
class A(j: JavaInterface) : JavaInterface by j
// MODULE: main(lib)
// FILE: main.kt
fun box(): String {
val t = object : JavaInterface {
override fun <K : Comparable<K>> foo(): K = "OK" as K
}
return A(t).foo<String>()
}
@@ -7544,6 +7544,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/IrConstAcceptMultiModule.kt");
}
@Test
@TestMetadata("javaTypeParameterBy.kt")
public void testJavaTypeParameterBy() throws Exception {
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/javaTypeParameterBy.kt");
}
@Test
@TestMetadata("LibraryProperty.kt")
public void testLibraryProperty() throws Exception {
@@ -7688,6 +7688,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/IrConstAcceptMultiModule.kt");
}
@Test
@TestMetadata("javaTypeParameterBy.kt")
public void testJavaTypeParameterBy() throws Exception {
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/javaTypeParameterBy.kt");
}
@Test
@TestMetadata("LibraryProperty.kt")
public void testLibraryProperty() throws Exception {
@@ -520,6 +520,12 @@ public class JvmIrAgainstOldBoxTestGenerated extends AbstractJvmIrAgainstOldBoxT
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/IrConstAcceptMultiModule.kt");
}
@Test
@TestMetadata("javaTypeParameterBy.kt")
public void testJavaTypeParameterBy() throws Exception {
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/javaTypeParameterBy.kt");
}
@Test
@TestMetadata("LibraryProperty.kt")
public void testLibraryProperty() throws Exception {
@@ -514,6 +514,12 @@ public class JvmOldAgainstIrBoxTestGenerated extends AbstractJvmOldAgainstIrBoxT
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/IrConstAcceptMultiModule.kt");
}
@Test
@TestMetadata("javaTypeParameterBy.kt")
public void testJavaTypeParameterBy() throws Exception {
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/javaTypeParameterBy.kt");
}
@Test
@TestMetadata("LibraryProperty.kt")
public void testLibraryProperty() throws Exception {