[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:
Dmitriy Novozhilov
2019-08-08 14:02:01 +03:00
parent e904e638e9
commit 38fa0122e8
4 changed files with 17 additions and 10 deletions
@@ -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 -> {
}
}
}