FIR: Do not call withReplacedConeType if type is unresolved

This commit is contained in:
Denis Zharkov
2020-09-23 14:37:44 +03:00
parent cb07ffc4fd
commit fd9c6479bf
@@ -404,7 +404,8 @@ class FirClassSubstitutionScope(
newReturnType: ConeKotlinType? = null
) {
annotations += baseFunction.annotations
returnTypeRef = baseFunction.returnTypeRef.withReplacedConeType(newReturnType)
returnTypeRef = replaceReturnTypeIfResolved(baseFunction, newReturnType)
if (this is FirSimpleFunctionBuilder) {
receiverTypeRef = baseFunction.receiverTypeRef?.withReplacedConeType(newReceiverType)
}
@@ -419,6 +420,14 @@ class FirClassSubstitutionScope(
}
}
private fun replaceReturnTypeIfResolved(
base: FirCallableDeclaration<*>,
newReturnType: ConeKotlinType?
) = if (base.returnTypeRef is FirResolvedTypeRef)
base.returnTypeRef.withReplacedConeType(newReturnType)
else
base.returnTypeRef
fun createFakeOverrideProperty(
session: FirSession,
baseProperty: FirProperty,
@@ -524,7 +533,7 @@ class FirClassSubstitutionScope(
newReturnType: ConeKotlinType? = null
) {
annotations += baseProperty.annotations
returnTypeRef = baseProperty.returnTypeRef.withReplacedConeType(newReturnType)
returnTypeRef = replaceReturnTypeIfResolved(baseProperty, newReturnType)
receiverTypeRef = baseProperty.receiverTypeRef?.withReplacedConeType(newReceiverType)
}