FIR: use type of last expression as type of branch, not type of block
This commit is contained in:
committed by
Mikhail Glukhikh
parent
fd279860f7
commit
d89913dc8d
+6
-1
@@ -529,7 +529,12 @@ open class FirBodyResolveTransformer(val session: FirSession, val implicitTypeOn
|
|||||||
whenExpression.transformChildren(this, data)
|
whenExpression.transformChildren(this, data)
|
||||||
if (whenExpression.resultType !is FirResolvedTypeRef) {
|
if (whenExpression.resultType !is FirResolvedTypeRef) {
|
||||||
val type = commonSuperType(whenExpression.branches.mapNotNull {
|
val type = commonSuperType(whenExpression.branches.mapNotNull {
|
||||||
it.result.resultType
|
val expression = it.result.statements.lastOrNull() as? FirExpression
|
||||||
|
if (expression != null) {
|
||||||
|
(expression.resultType as? FirResolvedTypeRef) ?: FirErrorTypeRefImpl(session, null, "No type for when branch result")
|
||||||
|
} else {
|
||||||
|
FirImplicitUnitTypeRef(session, null)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
if (type != null) whenExpression.resultType = type
|
if (type != null) whenExpression.resultType = type
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user