[FIR] add more information to ISE "Status should be resolved for a declaration to create it fake override" exception

^KT-62268
This commit is contained in:
Ilya Kirillov
2023-10-02 20:31:52 +02:00
committed by Space Team
parent 68c7673cb3
commit a3b67594ff
@@ -26,9 +26,11 @@ import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImplWithoutSource import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImplWithoutSource
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
import org.jetbrains.kotlin.name.CallableId import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.utils.addToStdlib.runIf import org.jetbrains.kotlin.utils.addToStdlib.runIf
import org.jetbrains.kotlin.utils.exceptions.checkWithAttachment
object FirFakeOverrideGenerator { object FirFakeOverrideGenerator {
fun createSubstitutionOverrideFunction( fun createSubstitutionOverrideFunction(
@@ -44,7 +46,7 @@ object FirFakeOverrideGenerator {
newParameterTypes: List<ConeKotlinType?>? = null, newParameterTypes: List<ConeKotlinType?>? = null,
newTypeParameters: List<FirTypeParameter>? = null, newTypeParameters: List<FirTypeParameter>? = null,
isExpect: Boolean = baseFunction.isExpect, isExpect: Boolean = baseFunction.isExpect,
callableCopySubstitutionForTypeUpdater: CallableCopySubstitution? = null callableCopySubstitutionForTypeUpdater: CallableCopySubstitution? = null,
): FirNamedFunctionSymbol { ): FirNamedFunctionSymbol {
createSubstitutionOverrideFunction( createSubstitutionOverrideFunction(
symbolForSubstitutionOverride, session, baseFunction, derivedClassLookupTag, symbolForSubstitutionOverride, session, baseFunction, derivedClassLookupTag,
@@ -114,7 +116,7 @@ object FirFakeOverrideGenerator {
newReturnType: ConeKotlinType? = null, newReturnType: ConeKotlinType? = null,
newModality: Modality? = null, newModality: Modality? = null,
newVisibility: Visibility? = null, newVisibility: Visibility? = null,
callableCopySubstitutionForTypeUpdater: CallableCopySubstitution? = null callableCopySubstitutionForTypeUpdater: CallableCopySubstitution? = null,
): FirSimpleFunction { ): FirSimpleFunction {
checkStatusIsResolved(baseFunction) checkStatusIsResolved(baseFunction)
@@ -151,7 +153,7 @@ object FirFakeOverrideGenerator {
newContextReceiverTypes: List<ConeKotlinType?>?, newContextReceiverTypes: List<ConeKotlinType?>?,
newTypeParameters: List<FirTypeParameterRef>?, newTypeParameters: List<FirTypeParameterRef>?,
isExpect: Boolean, isExpect: Boolean,
callableCopySubstitutionForTypeUpdater: CallableCopySubstitution? callableCopySubstitutionForTypeUpdater: CallableCopySubstitution?,
): FirConstructor { ): FirConstructor {
checkStatusIsResolved(baseConstructor) checkStatusIsResolved(baseConstructor)
@@ -328,7 +330,7 @@ object FirFakeOverrideGenerator {
newReturnType: ConeKotlinType? = null, newReturnType: ConeKotlinType? = null,
newTypeParameters: List<FirTypeParameter>? = null, newTypeParameters: List<FirTypeParameter>? = null,
isExpect: Boolean = baseProperty.isExpect, isExpect: Boolean = baseProperty.isExpect,
callableCopySubstitutionForTypeUpdater: CallableCopySubstitution? = null callableCopySubstitutionForTypeUpdater: CallableCopySubstitution? = null,
): FirPropertySymbol { ): FirPropertySymbol {
createCopyForFirProperty( createCopyForFirProperty(
symbolForSubstitutionOverride, baseProperty, derivedClassLookupTag, session, origin, symbolForSubstitutionOverride, baseProperty, derivedClassLookupTag, session, origin,
@@ -362,7 +364,7 @@ object FirFakeOverrideGenerator {
newReturnType: ConeKotlinType? = null, newReturnType: ConeKotlinType? = null,
newModality: Modality? = null, newModality: Modality? = null,
newVisibility: Visibility? = null, newVisibility: Visibility? = null,
callableCopySubstitutionForTypeUpdater: CallableCopySubstitution? = null callableCopySubstitutionForTypeUpdater: CallableCopySubstitution? = null,
): FirProperty { ): FirProperty {
checkStatusIsResolved(baseProperty) checkStatusIsResolved(baseProperty)
@@ -513,7 +515,7 @@ object FirFakeOverrideGenerator {
newReturnType: ConeKotlinType? = null, newReturnType: ConeKotlinType? = null,
newModality: Modality? = null, newModality: Modality? = null,
newVisibility: Visibility? = null, newVisibility: Visibility? = null,
callableCopySubstitutionForTypeUpdater: CallableCopySubstitution? = null callableCopySubstitutionForTypeUpdater: CallableCopySubstitution? = null,
): FirField { ): FirField {
return buildField { return buildField {
source = baseField.source source = baseField.source
@@ -544,7 +546,7 @@ object FirFakeOverrideGenerator {
newReceiverType: ConeKotlinType?, newReceiverType: ConeKotlinType?,
newContextReceiverTypes: List<ConeKotlinType?>?, newContextReceiverTypes: List<ConeKotlinType?>?,
newReturnType: ConeKotlinType?, newReturnType: ConeKotlinType?,
callableCopySubstitutionForTypeUpdater: CallableCopySubstitution? callableCopySubstitutionForTypeUpdater: CallableCopySubstitution?,
): List<FirTypeParameter> { ): List<FirTypeParameter> {
return when { return when {
baseProperty.typeParameters.isEmpty() -> { baseProperty.typeParameters.isEmpty() -> {
@@ -584,7 +586,7 @@ object FirFakeOverrideGenerator {
newReceiverType: ConeKotlinType?, newReceiverType: ConeKotlinType?,
newContextReceiverTypes: List<ConeKotlinType?>?, newContextReceiverTypes: List<ConeKotlinType?>?,
newReturnType: ConeKotlinType?, newReturnType: ConeKotlinType?,
substitutor: ConeSubstitutor substitutor: ConeSubstitutor,
): Triple<ConeKotlinType?, List<ConeKotlinType?>, Maybe<ConeKotlinType?>> { ): Triple<ConeKotlinType?, List<ConeKotlinType?>, Maybe<ConeKotlinType?>> {
val copiedReceiverType = newReceiverType?.let { val copiedReceiverType = newReceiverType?.let {
substitutor.substituteOrNull(it) substitutor.substituteOrNull(it)
@@ -617,7 +619,7 @@ object FirFakeOverrideGenerator {
newContextReceiverTypes: List<ConeKotlinType?>?, newContextReceiverTypes: List<ConeKotlinType?>?,
newReturnType: ConeKotlinType?, newReturnType: ConeKotlinType?,
callableCopySubstitutionForTypeUpdater: CallableCopySubstitution?, callableCopySubstitutionForTypeUpdater: CallableCopySubstitution?,
updateReceiver: Boolean = true updateReceiver: Boolean = true,
) { ) {
annotations += baseVariable.annotations annotations += baseVariable.annotations
@@ -688,7 +690,7 @@ object FirFakeOverrideGenerator {
symbolForOverride: FirBasedSymbol<*>, symbolForOverride: FirBasedSymbol<*>,
substitutor: ConeSubstitutor, substitutor: ConeSubstitutor,
origin: FirDeclarationOrigin, origin: FirDeclarationOrigin,
forceTypeParametersRecreation: Boolean = true forceTypeParametersRecreation: Boolean = true,
): Pair<List<FirTypeParameterRef>, ConeSubstitutor> { ): Pair<List<FirTypeParameterRef>, ConeSubstitutor> {
if (member.typeParameters.isEmpty()) return Pair(member.typeParameters, substitutor) if (member.typeParameters.isEmpty()) return Pair(member.typeParameters, substitutor)
val newTypeParameters = member.typeParameters.map { typeParameterRef -> val newTypeParameters = member.typeParameters.map { typeParameterRef ->
@@ -749,10 +751,16 @@ object FirFakeOverrideGenerator {
} }
private fun checkStatusIsResolved(member: FirCallableDeclaration) { private fun checkStatusIsResolved(member: FirCallableDeclaration) {
check(member.status is FirResolvedDeclarationStatus) { checkWithAttachment(
"Status should be resolved for a declaration to create it fake override, " + member.status is FirResolvedDeclarationStatus,
"otherwise the status of the fake override will never be resolved." + message = {
"The status was unresolved for ${member::class.java.simpleName}" "Status should be resolved for a declaration to create its fake override, " +
"otherwise the status of the fake override will never be resolved." +
"The status was unresolved for ${member::class.java.simpleName}"
}
) {
withFirEntry("declaration", member)
withEntry("declarationStatus", member.status) { it.toString() }
} }
} }
} }