[FIR] Add exhaustive checker for when expressions

Also remove generating default else branch introduced in 38fa0122 and 54eb4cf9
This commit is contained in:
Dmitriy Novozhilov
2019-10-15 12:52:02 +03:00
parent 25e853606e
commit f19a878948
93 changed files with 5003 additions and 5464 deletions
@@ -521,7 +521,6 @@ class ExpressionsConverter(
if (hasSubject) {
subject.bind(this)
}
var thereIsElse = false
for (entry in whenEntries) {
val branch = entry.firBlock
branches += if (!entry.isElse) {
@@ -533,15 +532,11 @@ class ExpressionsConverter(
FirWhenBranchImpl(null, firCondition, branch)
}
} else {
thereIsElse = true
FirWhenBranchImpl(
null, FirElseIfTrueCondition(null), branch
)
}
}
if (!thereIsElse) {
branches += FirWhenBranchImpl(null, FirElseIfTrueCondition(null), FirEmptyExpressionBlock())
}
}
}
@@ -865,10 +860,12 @@ class ExpressionsConverter(
return FirWhenExpressionImpl(null, null, null).apply {
val trueBranch = convertLoopBody(thenBlock)
branches += FirWhenBranchImpl(null, firCondition, trueBranch)
val elseBranch = convertLoopBody(elseBlock)
branches += FirWhenBranchImpl(
null, FirElseIfTrueCondition(null), elseBranch
)
elseBlock?.let {
val elseBranch = convertLoopBody(it)
branches += FirWhenBranchImpl(
null, FirElseIfTrueCondition(null), elseBranch
)
}
}
}