FIR: Fix incorrect type of block generated for inc operator

Previously, it was obtained from expected type of a variable being assigned,
but it's better to use the type of resulting expression

Initially this part was brought in 4ab0897d7d,
but as we see in commit message and tests it was all about unit-coercion
This commit is contained in:
Denis.Zharkov
2021-11-11 12:55:40 +03:00
committed by teamcityserver
parent a7859e0332
commit c0b6a593e0
17 changed files with 67 additions and 20 deletions
@@ -408,8 +408,8 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
TransformData.Data(value)
}
block.transformOtherChildren(transformer, data)
if (data is ResolutionMode.WithExpectedType && data.expectedTypeRef is FirResolvedTypeRef) {
// Top-down propagation: from the explicit type of the enclosing declaration to the block type
if (data is ResolutionMode.WithExpectedType && data.expectedTypeRef.coneTypeSafe<ConeKotlinType>()?.isUnitOrFlexibleUnit == true) {
// Unit-coercion
block.resultType = data.expectedTypeRef
} else {
// Bottom-up propagation: from the return type of the last expression in the block to the block type