diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index b931c003f70..47704b7d1e1 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -17403,6 +17403,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/nothingValue"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @TestMetadata("inNestedCall.kt") + public void testInNestedCall() throws Exception { + runTest("compiler/testData/codegen/box/nothingValue/inNestedCall.kt"); + } + @TestMetadata("nothingValueException.kt") public void testNothingValueException() throws Exception { runTest("compiler/testData/codegen/box/nothingValue/nothingValueException.kt"); diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/KotlinNothingValueExceptionLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/KotlinNothingValueExceptionLowering.kt index b80b3ab48d9..2d040c8403e 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/KotlinNothingValueExceptionLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/KotlinNothingValueExceptionLowering.kt @@ -43,12 +43,12 @@ class KotlinNothingValueExceptionLowering(val backendContext: CommonBackendConte // (although doing so by subverting the type system). backendContext.createIrBuilder(parent, expression.startOffset, expression.endOffset).run { irBlock(expression, null, context.irBuiltIns.nothingType) { - +changeTypeToUnit(expression) + +super.visitCall(changeTypeToUnit(expression)) +irCall(backendContext.ir.symbols.ThrowKotlinNothingValueException) } } } else { - expression + super.visitCall(expression) } private fun changeTypeToUnit(call: IrCall): IrCall = diff --git a/compiler/testData/codegen/box/nothingValue/inNestedCall.kt b/compiler/testData/codegen/box/nothingValue/inNestedCall.kt new file mode 100644 index 00000000000..52985d9c576 --- /dev/null +++ b/compiler/testData/codegen/box/nothingValue/inNestedCall.kt @@ -0,0 +1,6 @@ +fun nestedNothing(s: String) = + "" + if (s == "OK") s else barf() + +fun barf(): Nothing = throw NullPointerException() + +fun box() = nestedNothing("OK") \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 7d4d29ad8df..50ef76f836a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -18618,6 +18618,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/nothingValue"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @TestMetadata("inNestedCall.kt") + public void testInNestedCall() throws Exception { + runTest("compiler/testData/codegen/box/nothingValue/inNestedCall.kt"); + } + @TestMetadata("nothingValueException.kt") public void testNothingValueException() throws Exception { runTest("compiler/testData/codegen/box/nothingValue/nothingValueException.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 9f5caef081f..1b9787336b8 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -18618,6 +18618,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/nothingValue"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @TestMetadata("inNestedCall.kt") + public void testInNestedCall() throws Exception { + runTest("compiler/testData/codegen/box/nothingValue/inNestedCall.kt"); + } + @TestMetadata("nothingValueException.kt") public void testNothingValueException() throws Exception { runTest("compiler/testData/codegen/box/nothingValue/nothingValueException.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 6db275da011..0a8a2d2e66e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -17403,6 +17403,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/nothingValue"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @TestMetadata("inNestedCall.kt") + public void testInNestedCall() throws Exception { + runTest("compiler/testData/codegen/box/nothingValue/inNestedCall.kt"); + } + @TestMetadata("nothingValueException.kt") public void testNothingValueException() throws Exception { runTest("compiler/testData/codegen/box/nothingValue/nothingValueException.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 3b2466c371b..9b8ca8d30cf 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -14018,6 +14018,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/nothingValue"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } + @TestMetadata("inNestedCall.kt") + public void testInNestedCall() throws Exception { + runTest("compiler/testData/codegen/box/nothingValue/inNestedCall.kt"); + } + @TestMetadata("nothingValueException.kt") public void testNothingValueException() throws Exception { runTest("compiler/testData/codegen/box/nothingValue/nothingValueException.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 3f741719b51..5565b30d886 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -14083,6 +14083,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/nothingValue"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); } + @TestMetadata("inNestedCall.kt") + public void testInNestedCall() throws Exception { + runTest("compiler/testData/codegen/box/nothingValue/inNestedCall.kt"); + } + @TestMetadata("nothingValueException.kt") public void testNothingValueException() throws Exception { runTest("compiler/testData/codegen/box/nothingValue/nothingValueException.kt");