From fd9c6479bfa1920d09f9524bcd38ce89b9501574 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Wed, 23 Sep 2020 14:37:44 +0300 Subject: [PATCH] FIR: Do not call withReplacedConeType if type is unresolved --- .../fir/scopes/impl/FirClassSubstitutionScope.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt index 802e17eda42..0f0ee6dfdba 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt @@ -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) }