K2: Clarify condition for when-with-one-branch optimization

It's safe resolve the branch in the independent context when
resolution mode would require full completion and there's no expected type
This commit is contained in:
Denis.Zharkov
2023-02-01 12:55:07 +01:00
committed by Space Team
parent 1bacef4327
commit 65f1485dc9
@@ -68,7 +68,7 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirAbstractBodyRes
context.withWhenSubjectType(subjectType, components) {
when {
whenExpression.branches.isEmpty() -> {}
whenExpression.isOneBranch() && data is ResolutionMode.ContextIndependent -> {
whenExpression.isOneBranch() && data.forceFullCompletion && data !is ResolutionMode.WithExpectedType -> {
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