[AA] Remove classifiers from non-static declared member scopes
- The semantics of a non-static declared member scope should be as follows: For a variable `c: C` of class type `C`, the declared member scope should contain all members `x` accessible as `c.x` (visibility notwithstanding) which are *also* explicitly declared in `C`. - Classifiers are not accessible as properties of a variable `c`, only as static members of the class `C` itself, so non-static declared member scopes should not contain any classifiers. ^KT-61800
This commit is contained in:
committed by
Space Team
parent
8b24baade9
commit
5679acbbdb
+9
-6
@@ -105,7 +105,7 @@ internal class KtFirScopeProvider(
|
||||
): FirContainingNamesAwareScope {
|
||||
val combinedScope = getCombinedFirKotlinDeclaredMemberScope(classSymbol)
|
||||
return when (kind) {
|
||||
DeclaredMemberScopeKind.NON_STATIC -> FirNonStaticCallablesScope(combinedScope)
|
||||
DeclaredMemberScopeKind.NON_STATIC -> FirNonStaticCallablesOnlyScope(combinedScope)
|
||||
DeclaredMemberScopeKind.STATIC -> FirStaticScope(combinedScope)
|
||||
}
|
||||
}
|
||||
@@ -115,11 +115,14 @@ internal class KtFirScopeProvider(
|
||||
val scopeSession = getScopeSession()
|
||||
|
||||
val firScope = when (kind) {
|
||||
DeclaredMemberScopeKind.NON_STATIC -> JavaScopeProvider.getUseSiteMemberScope(
|
||||
firJavaClass,
|
||||
useSiteSession,
|
||||
scopeSession,
|
||||
memberRequiredPhase = FirResolvePhase.TYPES,
|
||||
// `FirNoClassifiersScope` is a workaround for non-static member scopes containing classifiers (see KT-61900).
|
||||
DeclaredMemberScopeKind.NON_STATIC -> FirNoClassifiersScope(
|
||||
JavaScopeProvider.getUseSiteMemberScope(
|
||||
firJavaClass,
|
||||
useSiteSession,
|
||||
scopeSession,
|
||||
memberRequiredPhase = FirResolvePhase.TYPES,
|
||||
)
|
||||
)
|
||||
DeclaredMemberScopeKind.STATIC -> JavaScopeProvider.getStaticScope(firJavaClass, useSiteSession, scopeSession) ?: return null
|
||||
}
|
||||
|
||||
+4
@@ -12,6 +12,10 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
/**
|
||||
* A base implementation for [FirNonStaticCallablesOnlyScope] and [FirDeclaredMembersOnlyScope], which both filter callables based on some
|
||||
* condition.
|
||||
*/
|
||||
internal abstract class FirCallableFilteringScope(private val baseScope: FirContainingNamesAwareScope) : FirContainingNamesAwareScope() {
|
||||
protected abstract fun isTargetCallable(callable: FirCallableSymbol<*>): Boolean
|
||||
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.fir.scopes
|
||||
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
|
||||
import org.jetbrains.kotlin.fir.scopes.FirDelegatingContainingNamesAwareScope
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
internal class FirNoClassifiersScope(delegate: FirContainingNamesAwareScope) : FirDelegatingContainingNamesAwareScope(delegate) {
|
||||
override fun getClassifierNames(): Set<Name> = emptySet()
|
||||
|
||||
override fun processClassifiersByNameWithSubstitution(name: Name, processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit) {
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.fir.scopes
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isStatic
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
/**
|
||||
* Excludes static callables and all classifiers.
|
||||
*/
|
||||
internal class FirNonStaticCallablesOnlyScope(
|
||||
private val delegate: FirContainingNamesAwareScope,
|
||||
) : FirCallableFilteringScope(delegate) {
|
||||
override fun isTargetCallable(callable: FirCallableSymbol<*>): Boolean = !callable.fir.isStatic
|
||||
|
||||
override fun processDeclaredConstructors(processor: (FirConstructorSymbol) -> Unit) {
|
||||
delegate.processDeclaredConstructors(processor)
|
||||
}
|
||||
|
||||
override fun getClassifierNames(): Set<Name> = emptySet()
|
||||
|
||||
override fun processClassifiersByNameWithSubstitution(name: Name, processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user