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:
committed by
Space Team
parent
1bacef4327
commit
65f1485dc9
+1
-1
@@ -68,7 +68,7 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirAbstractBodyRes
|
|||||||
context.withWhenSubjectType(subjectType, components) {
|
context.withWhenSubjectType(subjectType, components) {
|
||||||
when {
|
when {
|
||||||
whenExpression.branches.isEmpty() -> {}
|
whenExpression.branches.isEmpty() -> {}
|
||||||
whenExpression.isOneBranch() && data is ResolutionMode.ContextIndependent -> {
|
whenExpression.isOneBranch() && data.forceFullCompletion && data !is ResolutionMode.WithExpectedType -> {
|
||||||
whenExpression = whenExpression.transformBranches(transformer, ResolutionMode.ContextIndependent)
|
whenExpression = whenExpression.transformBranches(transformer, ResolutionMode.ContextIndependent)
|
||||||
whenExpression.resultType = whenExpression.branches.first().result.resultType
|
whenExpression.resultType = whenExpression.branches.first().result.resultType
|
||||||
// when with one branch cannot be completed if it's not already complete in the first place
|
// when with one branch cannot be completed if it's not already complete in the first place
|
||||||
|
|||||||
Reference in New Issue
Block a user