FIR: pass the explicit expected type to block type

This helps avoid adding redundant return Unit into block.
This commit is contained in:
Jinseong Jeon
2020-12-08 14:34:25 -08:00
committed by Dmitriy Novozhilov
parent 0ea6b32c01
commit 4ab0897d7d
7 changed files with 23 additions and 19 deletions
@@ -309,7 +309,13 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
TransformData.Data(value)
}
block.transformOtherChildren(transformer, data)
block.writeResultType(session)
if (data is ResolutionMode.WithExpectedType && data.expectedTypeRef is FirResolvedTypeRef) {
// Top-down propagation: from the explicit type of the enclosing declaration to the block type
block.resultType = data.expectedTypeRef
} else {
// Bottom-up propagation: from the return type of the last expression in the block to the block type
block.writeResultType(session)
}
dataFlowAnalyzer.exitBlock(block)
}