JVM_IR: remove an assertion that triggers due to a frontend bug

This commit is contained in:
pyos
2019-10-18 19:00:01 +02:00
committed by Alexander Udalov
parent e5cc0eec9c
commit 0c3dfca6ee
7 changed files with 43 additions and 3 deletions
@@ -590,9 +590,6 @@ class ExpressionCodegen(
val endLabel = Label()
val exhaustive = expression.branches.any { it.condition.isTrueConst() }
assert(exhaustive || expression.type.isUnit() || expression.type.isNothing()) {
"non-exhaustive conditional should return Unit: ${expression.dump()}"
}
for (branch in expression.branches) {
val elseLabel = Label()
if (branch.condition.isFalseConst() || branch.condition.isTrueConst()) {
@@ -619,6 +616,14 @@ class ExpressionCodegen(
mv.mark(elseLabel)
}
mv.mark(endLabel)
// NOTE: using a non-exhaustive if/when as an expression is invalid, so it should theoretically
// always return Unit. However, with the current frontend this is not always the case.
// Most notably, 1. when all branches return/break/continue, the type is Nothing;
// 2. the frontend may sometimes infer Any instead of Unit, probably due to a bug
// (see compiler/testData/codegen/box/controlStructures/ifIncompatibleBranches.kt).
// It should still be safe to produce a soon-to-be-discarded Unit. (What is not ok is
// inserting *any* code here, though, as its line number will be that of the last line
// of the last branch.)
return immaterialUnitValue
}
@@ -0,0 +1,10 @@
fun box(): String {
var s = "2"
var res = "Fail"
if (s == "1") {
false
} else if (s == "2") {
res = "OK"
}
return res
}
@@ -4838,6 +4838,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/controlStructures/ifConst2.kt");
}
@TestMetadata("ifIncompatibleBranches.kt")
public void testIfIncompatibleBranches() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/ifIncompatibleBranches.kt");
}
@TestMetadata("inRangeConditionsInWhen.kt")
public void testInRangeConditionsInWhen() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/inRangeConditionsInWhen.kt");
@@ -4838,6 +4838,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/controlStructures/ifConst2.kt");
}
@TestMetadata("ifIncompatibleBranches.kt")
public void testIfIncompatibleBranches() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/ifIncompatibleBranches.kt");
}
@TestMetadata("inRangeConditionsInWhen.kt")
public void testInRangeConditionsInWhen() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/inRangeConditionsInWhen.kt");
@@ -4808,6 +4808,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/controlStructures/ifConst2.kt");
}
@TestMetadata("ifIncompatibleBranches.kt")
public void testIfIncompatibleBranches() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/ifIncompatibleBranches.kt");
}
@TestMetadata("inRangeConditionsInWhen.kt")
public void testInRangeConditionsInWhen() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/inRangeConditionsInWhen.kt");
@@ -3963,6 +3963,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/controlStructures/ifConst2.kt");
}
@TestMetadata("ifIncompatibleBranches.kt")
public void testIfIncompatibleBranches() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/ifIncompatibleBranches.kt");
}
@TestMetadata("inRangeConditionsInWhen.kt")
public void testInRangeConditionsInWhen() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/inRangeConditionsInWhen.kt");
@@ -3973,6 +3973,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/controlStructures/ifConst2.kt");
}
@TestMetadata("ifIncompatibleBranches.kt")
public void testIfIncompatibleBranches() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/ifIncompatibleBranches.kt");
}
@TestMetadata("inRangeConditionsInWhen.kt")
public void testInRangeConditionsInWhen() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/inRangeConditionsInWhen.kt");