[FE 1.0] Correctly set USED_AS_EXPRESSION for unreachable when and if blocks

^KT-50028 Fixed
This commit is contained in:
Dmitriy Novozhilov
2021-12-06 14:05:19 +03:00
committed by teamcity
parent 7bcd3c7948
commit df2e9e3797
10 changed files with 131 additions and 9 deletions
@@ -812,17 +812,33 @@ class ControlFlowInformationProviderImpl private constructor(
for (element in pseudocode.getValueElements(value)) {
trace.record(USED_AS_EXPRESSION, element, isUsedAsExpression)
trace.record(USED_AS_RESULT_OF_LAMBDA, element, isUsedAsResultOfLambda)
if (isUsedAsExpression && element is KtTryExpression) {
trace.record(USED_AS_EXPRESSION, element.tryBlock, true)
for (catchClause in element.catchClauses) {
val body = catchClause.catchBody ?: continue
trace.record(USED_AS_EXPRESSION, body, true)
if (isUsedAsExpression) {
when (element) {
is KtTryExpression -> {
element.tryBlock.recordUsedAsExpression()
for (catchClause in element.catchClauses) {
catchClause.catchBody?.recordUsedAsExpression()
}
}
is KtIfExpression -> {
(element.then as? KtBlockExpression)?.recordUsedAsExpression()
(element.`else` as? KtBlockExpression)?.recordUsedAsExpression()
}
is KtWhenExpression -> {
for (entry in element.entries) {
(entry.expression as? KtBlockExpression)?.recordUsedAsExpression()
}
}
}
}
}
}
}
private fun KtExpression.recordUsedAsExpression() {
trace.record(USED_AS_EXPRESSION, this, true)
}
private fun checkForSuspendLambdaAndMarkParameters(pseudocode: Pseudocode) {
for (instruction in pseudocode.instructionsIncludingDeadCode) {
if (instruction is LocalFunctionDeclarationInstruction) {