[FIR2IR] Generate unconditional branch in exhaustive whens
This commit is contained in:
@@ -504,11 +504,25 @@ class Fir2IrVisitor(
|
||||
whenExpression.typeRef.toIrType(),
|
||||
origin
|
||||
).apply {
|
||||
var unconditionalBranchFound = false
|
||||
for (branch in whenExpression.branches) {
|
||||
if (branch.condition !is FirElseIfTrueCondition || branch.result.statements.isNotEmpty()) {
|
||||
if (branch.condition !is FirElseIfTrueCondition) {
|
||||
branches += branch.accept(this@Fir2IrVisitor, data) as IrBranch
|
||||
} else {
|
||||
unconditionalBranchFound = true
|
||||
if (branch.result.statements.isNotEmpty()) {
|
||||
branches += branch.accept(this@Fir2IrVisitor, data) as IrBranch
|
||||
}
|
||||
}
|
||||
}
|
||||
if (whenExpression.isExhaustive && !unconditionalBranchFound) {
|
||||
val irResult = IrCallImpl(
|
||||
startOffset, endOffset, irBuiltIns.nothingType, irBuiltIns.noWhenBranchMatchedExceptionSymbol
|
||||
)
|
||||
branches += IrElseBranchImpl(
|
||||
IrConstImpl.boolean(startOffset, endOffset, irBuiltIns.booleanType, true), irResult
|
||||
)
|
||||
}
|
||||
}
|
||||
if (subjectVariable == null) {
|
||||
irWhen
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
sealed class Season {
|
||||
object Warm: Season()
|
||||
object Cold: Season()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
sealed class Season {
|
||||
class Warm: Season()
|
||||
class Cold: Season()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// CHECK_CASES_COUNT: function=test count=0
|
||||
// CHECK_IF_COUNT: function=test count=3
|
||||
|
||||
|
||||
Reference in New Issue
Block a user