JVM IR: fix incorrect type of IrCheckNotNull intrinsic
It is not correct to assume that arg0 has been generated to have the same IrType as the whole expression. The reason it only backfired in throwing exceptions probably has to do with the fact that visitThrow might be the only place in ExpressionCodegen right now which uses the IrType from PromisedValue to make a decision on whether to generate checkcast. It seems suspicious that ExpressionCodegen.visitFieldAccess/visitCall return PromisedValue whose IrType mentions type parameters which are declared outside of the call site, but that should probably be investigated separately. #KT-48440 Fixed
This commit is contained in:
+12
@@ -15454,6 +15454,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/exclExcl/genericNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48440.kt")
|
||||
public void testKt48440() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/kt48440.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48440_2.kt")
|
||||
public void testKt48440_2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/kt48440_2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ object IrCheckNotNull : IntrinsicMethod() {
|
||||
override fun invoke(expression: IrFunctionAccessExpression, codegen: ExpressionCodegen, data: BlockInfo): PromisedValue? {
|
||||
val arg0 = expression.getValueArgument(0)!!.accept(codegen, data)
|
||||
if (AsmUtil.isPrimitive(arg0.type)) return arg0
|
||||
return object : PromisedValue(codegen, arg0.type, expression.type) {
|
||||
return object : PromisedValue(codegen, arg0.type, arg0.irType) {
|
||||
override fun materializeAt(target: Type, irTarget: IrType, castForReified: Boolean) =
|
||||
arg0.materialized().also { codegen.checkTopValueForNull() }.materializeAt(target, irTarget, castForReified)
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// IGNORE_BACKEND: WASM
|
||||
|
||||
fun test(): String {
|
||||
var exception: Throwable? = null
|
||||
val f = {
|
||||
exception = IllegalStateException("OK")
|
||||
}
|
||||
f()
|
||||
|
||||
if (exception != null) {
|
||||
throw exception!!
|
||||
} else {
|
||||
return "Fail"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String = try {
|
||||
test()
|
||||
} catch (e: IllegalStateException) {
|
||||
e.message!!
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// IGNORE_BACKEND: WASM
|
||||
|
||||
fun <T> id(t: T): T = t
|
||||
|
||||
fun test(b: Boolean): String {
|
||||
var exception: Throwable? = null
|
||||
if (b) {
|
||||
exception = IllegalStateException("OK")
|
||||
}
|
||||
|
||||
if (exception != null) {
|
||||
throw id(exception)!!
|
||||
} else {
|
||||
return "Fail"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String = try {
|
||||
test(true)
|
||||
} catch (e: IllegalStateException) {
|
||||
e.message!!
|
||||
}
|
||||
+12
@@ -15346,6 +15346,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/genericNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48440.kt")
|
||||
public void testKt48440() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/kt48440.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48440_2.kt")
|
||||
public void testKt48440_2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/kt48440_2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
|
||||
+12
@@ -15454,6 +15454,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/exclExcl/genericNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48440.kt")
|
||||
public void testKt48440() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/kt48440.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48440_2.kt")
|
||||
public void testKt48440_2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/kt48440_2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
|
||||
+10
@@ -12600,6 +12600,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/exclExcl/genericNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt48440.kt")
|
||||
public void testKt48440() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/kt48440.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt48440_2.kt")
|
||||
public void testKt48440_2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/kt48440_2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/primitive.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+10
@@ -11129,6 +11129,16 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/exclExcl/genericNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt48440.kt")
|
||||
public void testKt48440() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/kt48440.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt48440_2.kt")
|
||||
public void testKt48440_2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/kt48440_2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/primitive.kt");
|
||||
|
||||
Generated
+10
@@ -10535,6 +10535,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/genericNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt48440.kt")
|
||||
public void testKt48440() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/kt48440.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt48440_2.kt")
|
||||
public void testKt48440_2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/kt48440_2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/primitive.kt");
|
||||
|
||||
Generated
+10
@@ -10535,6 +10535,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/genericNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt48440.kt")
|
||||
public void testKt48440() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/kt48440.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt48440_2.kt")
|
||||
public void testKt48440_2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/kt48440_2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/primitive.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+10
@@ -5268,6 +5268,16 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/exclExcl"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("kt48440.kt")
|
||||
public void testKt48440() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/kt48440.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt48440_2.kt")
|
||||
public void testKt48440_2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/kt48440_2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/exclExcl/primitive.kt");
|
||||
|
||||
Reference in New Issue
Block a user