Fix deserialization exception for DNN types from Java
useCorrectedNullabilityForTypeParameters = true only might lead to something becomes a DNN when otherwise it wasn't. It seems safe to use it here, since if compiler has generated DNN, then it's OK to assume that it checked necessary conditions, and it's likely that it had useCorrectedNullabilityForTypeParameters = true as well, there. Anyway, it looks saner than having an exception here. Also, we assume here that metadata leading to exception might only be generated with ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated LF (at least, we don't have contradicting evidences), thus it's mostly a preparations in case we decide to enable ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated in 1.9. ^KT-55357 Fixed ^KT-55388 Related ^KT-36770 Related
This commit is contained in:
committed by
Space Team
parent
9e8e5c5a36
commit
fd7559893e
+6
@@ -28369,6 +28369,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/javaInterop/conflictingOverloadsForThrowableInheritors2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegationToJavaDnn.kt")
|
||||
public void testDelegationToJavaDnn() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/delegationToJavaDnn.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericSamProjectedOut.kt")
|
||||
public void testGenericSamProjectedOut() throws Exception {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// LANGUAGE: +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated
|
||||
// ISSUE: KT-55357
|
||||
|
||||
// MODULE: lib
|
||||
// FILE: J.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface J {
|
||||
@NotNull
|
||||
<T> T foo();
|
||||
}
|
||||
|
||||
// FILE: JImpl.java
|
||||
public class JImpl implements J {
|
||||
public <T> T foo() {
|
||||
return (T) "OK";
|
||||
}
|
||||
}
|
||||
// FILE: a.kt
|
||||
class C(val x: J) : J by x
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: a.kt
|
||||
|
||||
fun box(): String {
|
||||
return C(JImpl()).foo<String>()
|
||||
}
|
||||
+6
@@ -27439,6 +27439,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/conflictingOverloadsForThrowableInheritors2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegationToJavaDnn.kt")
|
||||
public void testDelegationToJavaDnn() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/delegationToJavaDnn.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericSamProjectedOut.kt")
|
||||
public void testGenericSamProjectedOut() throws Exception {
|
||||
|
||||
+6
@@ -28369,6 +28369,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/javaInterop/conflictingOverloadsForThrowableInheritors2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegationToJavaDnn.kt")
|
||||
public void testDelegationToJavaDnn() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/delegationToJavaDnn.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericSamProjectedOut.kt")
|
||||
public void testGenericSamProjectedOut() throws Exception {
|
||||
|
||||
+5
@@ -23157,6 +23157,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/javaInterop/conflictingOverloadsForThrowableInheritors2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegationToJavaDnn.kt")
|
||||
public void testDelegationToJavaDnn() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/delegationToJavaDnn.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericSamProjectedOut.kt")
|
||||
public void testGenericSamProjectedOut() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/genericSamProjectedOut.kt");
|
||||
|
||||
+2
-1
@@ -125,7 +125,8 @@ class TypeDeserializer(
|
||||
else ->
|
||||
KotlinTypeFactory.simpleType(attributes, constructor, arguments, proto.nullable).let {
|
||||
if (Flags.DEFINITELY_NOT_NULL_TYPE.get(proto.flags))
|
||||
DefinitelyNotNullType.makeDefinitelyNotNull(it) ?: error("null DefinitelyNotNullType for '$it'")
|
||||
DefinitelyNotNullType.makeDefinitelyNotNull(it, useCorrectedNullabilityForTypeParameters = true)
|
||||
?: error("null DefinitelyNotNullType for '$it'")
|
||||
else
|
||||
it
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user