FIR: Change the Fir2Ir handling of smart casts.
Generate the expression with the original type and then insert an implicit conversion. That matches the behavior of psi2ir better and therefore avoids breaking backend assumptions. In particular, IrGetValue expects the type of the underlying symbol and the type of the IrGetValue to be the same.
This commit is contained in:
@@ -899,7 +899,18 @@ class Fir2IrVisitor(
|
||||
}
|
||||
|
||||
override fun visitExpressionWithSmartcast(expressionWithSmartcast: FirExpressionWithSmartcast, data: Any?): IrElement {
|
||||
return visitQualifiedAccessExpression(expressionWithSmartcast, data)
|
||||
// Generate the expression with the original type and then cast it to the smart cast type.
|
||||
val value = expressionWithSmartcast.toIrExpression(expressionWithSmartcast.originalType).applyReceivers(expressionWithSmartcast)
|
||||
val castType = expressionWithSmartcast.typeRef.toIrType(session, declarationStorage)
|
||||
if (value.type == castType) return value
|
||||
return IrTypeOperatorCallImpl(
|
||||
value.startOffset,
|
||||
value.endOffset,
|
||||
castType,
|
||||
IrTypeOperator.IMPLICIT_CAST,
|
||||
castType,
|
||||
value
|
||||
)
|
||||
}
|
||||
|
||||
override fun visitCallableReferenceAccess(callableReferenceAccess: FirCallableReferenceAccess, data: Any?): IrElement {
|
||||
|
||||
Reference in New Issue
Block a user