[FIR] Add synthetic else branch to when if it's missing to LightTreeFirBuilder

This commit is contained in:
Dmitriy Novozhilov
2019-09-02 11:12:35 +03:00
parent 5c29af4b53
commit 54eb4cf928
@@ -497,6 +497,7 @@ class ExpressionsConverter(
if (hasSubject) { if (hasSubject) {
subject.bind(this) subject.bind(this)
} }
var thereIsElse = false
for (entry in whenEntries) { for (entry in whenEntries) {
val branch = entry.firBlock val branch = entry.firBlock
branches += if (!entry.isElse) { branches += if (!entry.isElse) {
@@ -508,11 +509,15 @@ class ExpressionsConverter(
FirWhenBranchImpl(null, firCondition, branch) FirWhenBranchImpl(null, firCondition, branch)
} }
} else { } else {
thereIsElse = true
FirWhenBranchImpl( FirWhenBranchImpl(
null, FirElseIfTrueCondition(null), branch null, FirElseIfTrueCondition(null), branch
) )
} }
} }
if (!thereIsElse) {
branches += FirWhenBranchImpl(null, FirElseIfTrueCondition(null), FirEmptyExpressionBlock())
}
} }
} }