[Wasm] Fix generation optimised when expression with Nothing type
Fixed #KT-62147
This commit is contained in:
+6
@@ -54019,6 +54019,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
|
||||
+6
@@ -54019,6 +54019,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
|
||||
+6
@@ -54019,6 +54019,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
|
||||
+6
-3
@@ -329,7 +329,10 @@ private fun BodyGenerator.genTableIntSwitch(
|
||||
body.buildBlock(resultType)
|
||||
}
|
||||
|
||||
resultType?.let { generateDefaultInitializerForType(it, body) } //stub value
|
||||
if (resultType != null && resultType !is WasmUnreachableType) {
|
||||
generateDefaultInitializerForType(resultType, body) //stub value
|
||||
}
|
||||
|
||||
body.buildGetLocal(selectorLocal, location)
|
||||
if (shift != 0) {
|
||||
body.buildConstI32(shift, location)
|
||||
@@ -344,7 +347,7 @@ private fun BodyGenerator.genTableIntSwitch(
|
||||
body.buildEnd()
|
||||
|
||||
for (expression in branches) {
|
||||
if (resultType != null) {
|
||||
if (resultType != null && resultType !is WasmUnreachableType) {
|
||||
body.buildDrop(location)
|
||||
}
|
||||
generateWithExpectedType(expression.expression, expectedType)
|
||||
@@ -354,7 +357,7 @@ private fun BodyGenerator.genTableIntSwitch(
|
||||
}
|
||||
|
||||
if (elseExpression != null) {
|
||||
if (resultType != null) {
|
||||
if (resultType != null && resultType !is WasmUnreachableType) {
|
||||
body.buildDrop(location)
|
||||
}
|
||||
generateWithExpectedType(elseExpression, expectedType)
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
fun nothingTypedWhenSimple(c: Int): Int {
|
||||
val nothing = when(c) {
|
||||
2 -> return 2
|
||||
3 -> return 5
|
||||
4 -> return 1
|
||||
5 -> return 6
|
||||
6 -> return 9
|
||||
else -> return 7746353
|
||||
}
|
||||
}
|
||||
|
||||
fun nothingTypedWhenMixed(c: Int): Int {
|
||||
val nothing = when(c) {
|
||||
2 -> return 2
|
||||
3 -> return 5
|
||||
23 -> return 211
|
||||
44 -> return 666
|
||||
11 -> return 43
|
||||
43 -> return 53
|
||||
55 -> return 2
|
||||
99 -> return 81
|
||||
3 -> return 21
|
||||
212 -> return 5
|
||||
66 -> return 1
|
||||
5 -> return 611
|
||||
6 -> return 12
|
||||
123 -> return 63
|
||||
1 -> return 11
|
||||
5 -> return 19
|
||||
6 -> return 9
|
||||
else -> return 7746353
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (nothingTypedWhenSimple(4) != 1) return "fail1"
|
||||
if (nothingTypedWhenMixed(99) != 81) return "fail2"
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -50773,6 +50773,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
|
||||
+6
@@ -54019,6 +54019,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
|
||||
+6
@@ -54019,6 +54019,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
|
||||
+5
@@ -43689,6 +43689,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nullableWhen.kt");
|
||||
|
||||
+6
@@ -37471,6 +37471,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
|
||||
Generated
+6
@@ -37471,6 +37471,12 @@ public class FirJsES6CodegenBoxTestGenerated extends AbstractFirJsES6CodegenBoxT
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
|
||||
+6
@@ -37471,6 +37471,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
|
||||
+6
@@ -37471,6 +37471,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
|
||||
+6
@@ -41001,6 +41001,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
|
||||
+6
@@ -42055,6 +42055,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
|
||||
+6
@@ -40475,6 +40475,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
|
||||
+6
@@ -41002,6 +41002,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
|
||||
Generated
+6
@@ -37141,6 +37141,12 @@ public class FirWasmCodegenBoxTestGenerated extends AbstractFirWasmCodegenBoxTes
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
|
||||
Generated
+6
@@ -37141,6 +37141,12 @@ public class K1WasmCodegenBoxTestGenerated extends AbstractK1WasmCodegenBoxTest
|
||||
runTest("compiler/testData/codegen/box/when/noElseNoMatch.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nothingTyped.kt")
|
||||
public void testNothingTyped() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/nothingTyped.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableWhen.kt")
|
||||
public void testNullableWhen() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user