JVM IR: fix isMarkedNullable for nullability-flexible types
Since nullability-flexible types in IR are represented by an annotation on an IrSimpleType, not a special instance, the common implementation of `KotlinTypeMarker.isMarkedNullable` in `TypeSystemContext` doesn't work. This method is used for example to generate `typeOf` in JVM IR, in `TypeSystemCommonBackendContext.generateTypeOf`, and this issue led to a difference in behavior of `typeOf` for nullability-flexible types. #KT-44726 Fixed
This commit is contained in:
+6
@@ -35417,6 +35417,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/reflection/typeOf/classes.kt");
|
runTest("compiler/testData/codegen/box/reflection/typeOf/classes.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("flexibleType.kt")
|
||||||
|
public void testFlexibleType() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/typeOf/flexibleType.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("inlineClasses.kt")
|
@TestMetadata("inlineClasses.kt")
|
||||||
public void testInlineClasses() throws Exception {
|
public void testInlineClasses() throws Exception {
|
||||||
|
|||||||
@@ -77,6 +77,9 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
|||||||
|
|
||||||
override fun SimpleTypeMarker.isMarkedNullable(): Boolean = (this as IrSimpleType).hasQuestionMark
|
override fun SimpleTypeMarker.isMarkedNullable(): Boolean = (this as IrSimpleType).hasQuestionMark
|
||||||
|
|
||||||
|
override fun KotlinTypeMarker.isMarkedNullable(): Boolean =
|
||||||
|
this is IrSimpleType && !isWithFlexibleNullability() && hasQuestionMark
|
||||||
|
|
||||||
override fun SimpleTypeMarker.withNullability(nullable: Boolean): SimpleTypeMarker {
|
override fun SimpleTypeMarker.withNullability(nullable: Boolean): SimpleTypeMarker {
|
||||||
val simpleType = this as IrSimpleType
|
val simpleType = this as IrSimpleType
|
||||||
return if (simpleType.hasQuestionMark == nullable) simpleType
|
return if (simpleType.hasQuestionMark == nullable) simpleType
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi
|
||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
|
// WITH_REFLECT
|
||||||
|
// FILE: box.kt
|
||||||
|
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlin.reflect.*
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val v = returnTypeOf { J.get() }.toString()
|
||||||
|
if (v != "J") return "Fail: $v"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <reified T: Any> returnTypeOf(block: () -> T) =
|
||||||
|
typeOf<T>()
|
||||||
|
|
||||||
|
// FILE: J.java
|
||||||
|
|
||||||
|
public class J {
|
||||||
|
public static J get() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -35417,6 +35417,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/reflection/typeOf/classes.kt");
|
runTest("compiler/testData/codegen/box/reflection/typeOf/classes.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("flexibleType.kt")
|
||||||
|
public void testFlexibleType() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/typeOf/flexibleType.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("inlineClasses.kt")
|
@TestMetadata("inlineClasses.kt")
|
||||||
public void testInlineClasses() throws Exception {
|
public void testInlineClasses() throws Exception {
|
||||||
|
|||||||
+6
@@ -35417,6 +35417,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/reflection/typeOf/classes.kt");
|
runTest("compiler/testData/codegen/box/reflection/typeOf/classes.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("flexibleType.kt")
|
||||||
|
public void testFlexibleType() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/typeOf/flexibleType.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("inlineClasses.kt")
|
@TestMetadata("inlineClasses.kt")
|
||||||
public void testInlineClasses() throws Exception {
|
public void testInlineClasses() throws Exception {
|
||||||
|
|||||||
+5
@@ -28146,6 +28146,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/reflection/typeOf/classes.kt");
|
runTest("compiler/testData/codegen/box/reflection/typeOf/classes.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("flexibleType.kt")
|
||||||
|
public void testFlexibleType() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/typeOf/flexibleType.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inlineClasses.kt")
|
@TestMetadata("inlineClasses.kt")
|
||||||
public void testInlineClasses() throws Exception {
|
public void testInlineClasses() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/reflection/typeOf/inlineClasses.kt");
|
runTest("compiler/testData/codegen/box/reflection/typeOf/inlineClasses.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user