FirClassSubstitutionScope: handle fake override local eff. visibility

This commit is contained in:
Mikhail Glukhikh
2020-06-02 18:31:09 +03:00
parent 21498359e4
commit 5603afbd20
@@ -6,9 +6,11 @@
package org.jetbrains.kotlin.fir.scopes.impl package org.jetbrains.kotlin.fir.scopes.impl
import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.fir.FirEffectiveVisibilityImpl
import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.builder.* import org.jetbrains.kotlin.fir.declarations.builder.*
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
import org.jetbrains.kotlin.fir.declarations.synthetic.buildSyntheticProperty import org.jetbrains.kotlin.fir.declarations.synthetic.buildSyntheticProperty
import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.ScopeSession
@@ -276,6 +278,7 @@ class FirClassSubstitutionScope(
companion object { companion object {
private fun FirFunctionBuilder.configureAnnotationsAndParameters( private fun FirFunctionBuilder.configureAnnotationsAndParameters(
session: FirSession,
baseFunction: FirFunction<*>, baseFunction: FirFunction<*>,
newParameterTypes: List<ConeKotlinType?>? newParameterTypes: List<ConeKotlinType?>?
) { ) {
@@ -298,6 +301,14 @@ class FirClassSubstitutionScope(
} }
} }
private fun FirDeclarationStatus.withLocalEffectiveVisibility(isLocal: Boolean): FirDeclarationStatus {
return if (isLocal && this is FirDeclarationStatusImpl) {
resolved(visibility, FirEffectiveVisibilityImpl.Local, modality!!)
} else {
this
}
}
private fun createFakeOverrideFunction( private fun createFakeOverrideFunction(
fakeOverrideSymbol: FirFunctionSymbol<FirSimpleFunction>, fakeOverrideSymbol: FirFunctionSymbol<FirSimpleFunction>,
session: FirSession, session: FirSession,
@@ -309,6 +320,7 @@ class FirClassSubstitutionScope(
): FirSimpleFunction { ): FirSimpleFunction {
// 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
val isLocal = fakeOverrideSymbol.callableId.classId?.isLocal == true
return buildSimpleFunction { return buildSimpleFunction {
source = baseFunction.source source = baseFunction.source
this.session = session this.session = session
@@ -316,10 +328,10 @@ class FirClassSubstitutionScope(
returnTypeRef = baseFunction.returnTypeRef.withReplacedReturnType(newReturnType) returnTypeRef = baseFunction.returnTypeRef.withReplacedReturnType(newReturnType)
receiverTypeRef = baseFunction.receiverTypeRef?.withReplacedConeType(newReceiverType) receiverTypeRef = baseFunction.receiverTypeRef?.withReplacedConeType(newReceiverType)
name = baseFunction.name name = baseFunction.name
status = baseFunction.status status = baseFunction.status.withLocalEffectiveVisibility(isLocal)
symbol = fakeOverrideSymbol symbol = fakeOverrideSymbol
resolvePhase = baseFunction.resolvePhase resolvePhase = baseFunction.resolvePhase
configureAnnotationsAndParameters(baseFunction, newParameterTypes) configureAnnotationsAndParameters(session, baseFunction, newParameterTypes)
// TODO: Fix the hack for org.jetbrains.kotlin.fir.backend.Fir2IrVisitor.addFakeOverrides // TODO: Fix the hack for org.jetbrains.kotlin.fir.backend.Fir2IrVisitor.addFakeOverrides
// We might have added baseFunction.typeParameters in case new ones are null // We might have added baseFunction.typeParameters in case new ones are null
@@ -375,7 +387,7 @@ class FirClassSubstitutionScope(
isVar = baseProperty.isVar isVar = baseProperty.isVar
this.symbol = symbol this.symbol = symbol
isLocal = false isLocal = false
status = baseProperty.status status = baseProperty.status.withLocalEffectiveVisibility(isLocal)
resolvePhase = baseProperty.resolvePhase resolvePhase = baseProperty.resolvePhase
annotations += baseProperty.annotations annotations += baseProperty.annotations
if (newTypeParameters != null) { if (newTypeParameters != null) {
@@ -448,7 +460,7 @@ class FirClassSubstitutionScope(
status = baseConstructor.status status = baseConstructor.status
symbol = fakeOverrideSymbol symbol = fakeOverrideSymbol
resolvePhase = baseConstructor.resolvePhase resolvePhase = baseConstructor.resolvePhase
configureAnnotationsAndParameters(baseConstructor, newParameterTypes) configureAnnotationsAndParameters(session, baseConstructor, newParameterTypes)
// TODO: Fix the hack for org.jetbrains.kotlin.fir.backend.Fir2IrVisitor.addFakeOverrides // TODO: Fix the hack for org.jetbrains.kotlin.fir.backend.Fir2IrVisitor.addFakeOverrides
// We might have added baseFunction.typeParameters in case new ones are null // We might have added baseFunction.typeParameters in case new ones are null