[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
This commit is contained in:
Ilya Kirillov
2023-02-01 12:36:01 +01:00
committed by Space Team
parent 7c8f7bdbfb
commit cc52e896f9
@@ -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. * 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, newVisibility: Visibility? = null,
fakeOverrideSubstitution: FakeOverrideSubstitution? = null fakeOverrideSubstitution: FakeOverrideSubstitution? = null
): FirSimpleFunction { ): FirSimpleFunction {
checkStatusIsResolved(baseFunction)
return buildSimpleFunction { return buildSimpleFunction {
source = baseFunction.source source = baseFunction.source
moduleData = session.nullableModuleData ?: baseFunction.moduleData moduleData = session.nullableModuleData ?: baseFunction.moduleData
@@ -147,6 +149,8 @@ object FirFakeOverrideGenerator {
isExpect: Boolean, isExpect: Boolean,
fakeOverrideSubstitution: FakeOverrideSubstitution? fakeOverrideSubstitution: FakeOverrideSubstitution?
): FirConstructor { ): FirConstructor {
checkStatusIsResolved(baseConstructor)
// TODO: consider using here some light-weight functions instead of pseudo-real FirMemberFunctionImpl // 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 // As second alternative, we can invent some light-weight kind of FirRegularClass
return buildConstructor { return buildConstructor {
@@ -350,6 +354,8 @@ object FirFakeOverrideGenerator {
newVisibility: Visibility? = null, newVisibility: Visibility? = null,
fakeOverrideSubstitution: FakeOverrideSubstitution? = null fakeOverrideSubstitution: FakeOverrideSubstitution? = null
): FirProperty { ): FirProperty {
checkStatusIsResolved(baseProperty)
return buildProperty { return buildProperty {
source = baseProperty.source source = baseProperty.source
moduleData = session.moduleData moduleData = session.moduleData
@@ -724,4 +730,12 @@ object FirFakeOverrideGenerator {
class Value<out A>(val value: A) : Maybe<A>() class Value<out A>(val value: A) : Maybe<A>()
object Nothing : Maybe<kotlin.Nothing>() object Nothing : Maybe<kotlin.Nothing>()
} }
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}"
}
}
} }