[FIR] Add synthetic else branch to when if it's missing
This change is needed for correct work of data flow, because for non-exhaustive when there is a else branch in terms of control flow graph. This change leads to some errors when when is actually exhaustive, but we still add else branch. Those errors will be gone when exhaustive checker will be introduced
This commit is contained in:
@@ -943,6 +943,7 @@ class RawFirBuilder(session: FirSession, val stubMode: Boolean) : BaseFirBuilder
|
||||
if (hasSubject) {
|
||||
subject.bind(this)
|
||||
}
|
||||
var thereIsElseBranch = false
|
||||
for (entry in expression.entries) {
|
||||
val branch = entry.expression.toFirBlock()
|
||||
branches += if (!entry.isElse) {
|
||||
@@ -960,9 +961,13 @@ class RawFirBuilder(session: FirSession, val stubMode: Boolean) : BaseFirBuilder
|
||||
FirWhenBranchImpl(entry, firCondition, branch)
|
||||
}
|
||||
} else {
|
||||
thereIsElseBranch = true
|
||||
FirWhenBranchImpl(entry, FirElseIfTrueCondition(null), branch)
|
||||
}
|
||||
}
|
||||
if (!thereIsElseBranch) {
|
||||
branches += FirWhenBranchImpl(null, FirElseIfTrueCondition(null), FirEmptyExpressionBlock())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@ FILE: recursiveCallOnWhenWithSealedClass.kt
|
||||
($subj$ is R|Maybe.Yeah|) -> {
|
||||
<Unresolved name: meat>#
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user