[FIR] Infer type of elvis from lhs if rhs is Nothing

^KT-50875 Fixed
This commit is contained in:
Dmitriy Novozhilov
2022-01-21 17:42:14 +03:00
parent 83ff0946fe
commit d1fb8338ef
8 changed files with 73 additions and 4 deletions
@@ -243,6 +243,14 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirBodyResolveTran
}
}
if (result.rhs.typeRef.coneTypeSafe<ConeKotlinType>()?.isNothing == true) {
val lhsType = result.lhs.typeRef.coneTypeSafe<ConeKotlinType>()
if (lhsType != null) {
val newReturnType = lhsType.makeConeTypeDefinitelyNotNullOrNotNull(session.typeContext)
result.replaceTypeRef(result.typeRef.resolvedTypeFromPrototype(newReturnType))
}
}
session.typeContext.run {
if (result.typeRef.coneTypeSafe<ConeKotlinType>()?.isNullableType() == true
&& result.rhs.typeRef.coneTypeSafe<ConeKotlinType>()?.isNullableType() == false
@@ -255,8 +263,6 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirBodyResolveTran
}
}
dataFlowAnalyzer.exitElvis(elvisExpression)
return result
}