From cc52e896f9bc04cdd7cc47278a24ef589686bd6a Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Wed, 1 Feb 2023 12:36:01 +0100 Subject: [PATCH] [FIR] ensure that status is resolved when we create fake overrides We should create the fake override only when we already have resolved status. Otherwise, the fake override declaration will be created with unresolved status, and its status will never be computed as we do not resolve fake override declarations. ^KT-56543 --- .../fir/scopes/impl/FirFakeOverrideGenerator.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt index 568615b4f13..98463e4e16b 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -112,6 +112,8 @@ object FirFakeOverrideGenerator { newVisibility: Visibility? = null, fakeOverrideSubstitution: FakeOverrideSubstitution? = null ): FirSimpleFunction { + checkStatusIsResolved(baseFunction) + return buildSimpleFunction { source = baseFunction.source moduleData = session.nullableModuleData ?: baseFunction.moduleData @@ -147,6 +149,8 @@ object FirFakeOverrideGenerator { isExpect: Boolean, fakeOverrideSubstitution: FakeOverrideSubstitution? ): FirConstructor { + checkStatusIsResolved(baseConstructor) + // TODO: consider using here some light-weight functions instead of pseudo-real FirMemberFunctionImpl // As second alternative, we can invent some light-weight kind of FirRegularClass return buildConstructor { @@ -350,6 +354,8 @@ object FirFakeOverrideGenerator { newVisibility: Visibility? = null, fakeOverrideSubstitution: FakeOverrideSubstitution? = null ): FirProperty { + checkStatusIsResolved(baseProperty) + return buildProperty { source = baseProperty.source moduleData = session.moduleData @@ -724,4 +730,12 @@ object FirFakeOverrideGenerator { class Value(val value: A) : Maybe() object Nothing : Maybe() } + + private fun checkStatusIsResolved(member: FirCallableDeclaration) { + check(member.status is FirResolvedDeclarationStatus) { + "Status should be resolved for a declaration to create it fake override, " + + "otherwise the status of the fake override will never be resolved." + + "The status was unresolved for ${member::class.java.simpleName}" + } + } }