K2: Optimize one-branch when-expr case only for independent context

Using independent one where `when` is nested doesn't look correct
This commit is contained in:
Denis.Zharkov
2022-11-23 14:02:04 +01:00
committed by Space Team
parent 04d3996e68
commit 8f8ea8c57f
7 changed files with 9 additions and 68 deletions
@@ -68,7 +68,7 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirAbstractBodyRes
context.withWhenSubjectType(subjectType, components) {
when {
whenExpression.branches.isEmpty() -> {}
whenExpression.isOneBranch() -> {
whenExpression.isOneBranch() && data is ResolutionMode.ContextIndependent -> {
whenExpression = whenExpression.transformBranches(transformer, ResolutionMode.ContextIndependent)
whenExpression.resultType = whenExpression.branches.first().result.resultType
// when with one branch cannot be completed if it's not already complete in the first place