[FIR] Completely unwrap original argument when computing type arguments

When computing the conversion type for a type operator call, the
argument needs to be fully unwrapped before getting the resolved type.
This avoids the situation when the argument is a when-subject and the
assumed original type is not correct. Before, only smart-casts were
unwrapped, and this change will also unwrap when-subjects (as well as a
few other FirExpressions).

^KT-62114 Fixed
This commit is contained in:
Brian Norman
2023-10-04 16:48:49 -05:00
committed by Space Team
parent 23bdfd226f
commit 2e6dbbe020
5 changed files with 88 additions and 1 deletions
@@ -151,6 +151,16 @@ fun FirVariableAssignment.unwrapLValue(): FirQualifiedAccessExpression? {
val FirElement.calleeReference: FirReference?
get() = (this as? FirResolvable)?.calleeReference ?: (this as? FirVariableAssignment)?.calleeReference
fun FirExpression.unwrapExpression(): FirExpression =
when (this) {
is FirWhenSubjectExpression -> whenRef.value.subject?.unwrapExpression() ?: this
is FirSmartCastExpression -> originalExpression.unwrapExpression()
is FirCheckedSafeCallSubject -> originalReceiverRef.value.unwrapExpression()
is FirCheckNotNullCall -> argument.unwrapExpression()
is FirDesugaredAssignmentValueReferenceExpression -> expressionRef.value.unwrapExpression()
else -> this
}
fun FirExpression.unwrapSmartcastExpression(): FirExpression =
when (this) {
is FirSmartCastExpression -> originalExpression