FIR body resolve: use nested classifier scopes only via member scopes
This commit is contained in:
+4
@@ -72,6 +72,10 @@ class JavaClassEnhancementScope(
|
|||||||
return super.processFunctionsByName(name, processor)
|
return super.processFunctionsByName(name, processor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun processClassifiersByName(name: Name, processor: (FirClassifierSymbol<*>) -> ProcessorAction): ProcessorAction {
|
||||||
|
return useSiteMemberScope.processClassifiersByName(name, processor)
|
||||||
|
}
|
||||||
|
|
||||||
private fun enhance(
|
private fun enhance(
|
||||||
original: FirCallableSymbol<*>,
|
original: FirCallableSymbol<*>,
|
||||||
name: Name
|
name: Name
|
||||||
|
|||||||
+14
@@ -53,6 +53,7 @@ class ConeOverloadConflictResolver(
|
|||||||
is FirSimpleFunction -> createFlatSignature(call, declaration)
|
is FirSimpleFunction -> createFlatSignature(call, declaration)
|
||||||
is FirConstructor -> createFlatSignature(call, declaration)
|
is FirConstructor -> createFlatSignature(call, declaration)
|
||||||
is FirVariable<*> -> createFlatSignature(call, declaration)
|
is FirVariable<*> -> createFlatSignature(call, declaration)
|
||||||
|
is FirClass<*> -> createFlatSignature(call, declaration)
|
||||||
else -> error("Not supported: $declaration")
|
else -> error("Not supported: $declaration")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,6 +113,19 @@ class ConeOverloadConflictResolver(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createFlatSignature(call: Candidate, klass: FirClass<*>): FlatSignature<Candidate> {
|
||||||
|
return FlatSignature(
|
||||||
|
call,
|
||||||
|
(klass as? FirRegularClass)?.typeParameters?.map { it.symbol }.orEmpty(),
|
||||||
|
valueParameterTypes = emptyList(),
|
||||||
|
hasExtensionReceiver = false,
|
||||||
|
hasVarargs = false,
|
||||||
|
numDefaults = 0,
|
||||||
|
isExpect = (klass as? FirRegularClass)?.isExpect == true,
|
||||||
|
isSyntheticMember = false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun createEmptyConstraintSystem(): SimpleConstraintSystem {
|
private fun createEmptyConstraintSystem(): SimpleConstraintSystem {
|
||||||
return ConeSimpleConstraintSystemImpl(inferenceComponents.createConstraintSystem())
|
return ConeSimpleConstraintSystemImpl(inferenceComponents.createConstraintSystem())
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -117,7 +117,7 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb
|
|||||||
qualifiedResolver
|
qualifiedResolver
|
||||||
)
|
)
|
||||||
val typeResolverTransformer = FirSpecificTypeResolverTransformer(
|
val typeResolverTransformer = FirSpecificTypeResolverTransformer(
|
||||||
FirTypeResolveScopeForBodyResolve(topLevelScopes, localScopes), session
|
FirTypeResolveScopeForBodyResolve(topLevelScopes, implicitReceiverStack, localScopes), session
|
||||||
)
|
)
|
||||||
val callCompleter: FirCallCompleter = FirCallCompleter(transformer, this)
|
val callCompleter: FirCallCompleter = FirCallCompleter(transformer, this)
|
||||||
val dataFlowAnalyzer: FirDataFlowAnalyzer = FirDataFlowAnalyzer(this)
|
val dataFlowAnalyzer: FirDataFlowAnalyzer = FirDataFlowAnalyzer(this)
|
||||||
|
|||||||
-8
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.fir.resolve.transformers.transformVarargTypeToArrayT
|
|||||||
import org.jetbrains.kotlin.fir.resolvedTypeFromPrototype
|
import org.jetbrains.kotlin.fir.resolvedTypeFromPrototype
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirLocalScope
|
import org.jetbrains.kotlin.fir.scopes.impl.FirLocalScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirMemberTypeParameterScope
|
import org.jetbrains.kotlin.fir.scopes.impl.FirMemberTypeParameterScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.nestedClassifierScope
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.impl.FirComputingImplicitTypeRef
|
import org.jetbrains.kotlin.fir.types.impl.FirComputingImplicitTypeRef
|
||||||
@@ -229,11 +228,6 @@ class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransformer)
|
|||||||
if (regularClass.symbol.classId.isLocal) {
|
if (regularClass.symbol.classId.isLocal) {
|
||||||
prepareLocalClassForBodyResolve(regularClass)
|
prepareLocalClassForBodyResolve(regularClass)
|
||||||
}
|
}
|
||||||
val companionObject = regularClass.companionObject
|
|
||||||
if (companionObject != null) {
|
|
||||||
topLevelScopes += nestedClassifierScope(companionObject)
|
|
||||||
}
|
|
||||||
topLevelScopes += nestedClassifierScope(regularClass)
|
|
||||||
|
|
||||||
val oldConstructorScope = primaryConstructorParametersScope
|
val oldConstructorScope = primaryConstructorParametersScope
|
||||||
val oldContainingClass = containingClass
|
val oldContainingClass = containingClass
|
||||||
@@ -258,8 +252,6 @@ class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransformer)
|
|||||||
override fun transformAnonymousObject(anonymousObject: FirAnonymousObject, data: ResolutionMode): CompositeTransformResult<FirStatement> {
|
override fun transformAnonymousObject(anonymousObject: FirAnonymousObject, data: ResolutionMode): CompositeTransformResult<FirStatement> {
|
||||||
prepareLocalClassForBodyResolve(anonymousObject)
|
prepareLocalClassForBodyResolve(anonymousObject)
|
||||||
return withScopeCleanup(topLevelScopes) {
|
return withScopeCleanup(topLevelScopes) {
|
||||||
topLevelScopes += nestedClassifierScope(anonymousObject)
|
|
||||||
|
|
||||||
val type = anonymousObject.defaultType()
|
val type = anonymousObject.defaultType()
|
||||||
anonymousObject.resultType = FirResolvedTypeRefImpl(anonymousObject.source, type)
|
anonymousObject.resultType = FirResolvedTypeRefImpl(anonymousObject.source, type)
|
||||||
val result = withLabelAndReceiverType(null, anonymousObject, type) {
|
val result = withLabelAndReceiverType(null, anonymousObject, type) {
|
||||||
|
|||||||
+4
-1
@@ -42,6 +42,9 @@ abstract class AbstractFirUseSiteMemberScope(
|
|||||||
name: Name,
|
name: Name,
|
||||||
processor: (FirClassifierSymbol<*>) -> ProcessorAction
|
processor: (FirClassifierSymbol<*>) -> ProcessorAction
|
||||||
): ProcessorAction {
|
): ProcessorAction {
|
||||||
return declaredMemberScope.processClassifiersByName(name, processor)
|
if (!declaredMemberScope.processClassifiersByName(name, processor)) {
|
||||||
|
return ProcessorAction.NEXT
|
||||||
|
}
|
||||||
|
return superTypesScope.processClassifiersByName(name, processor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
@@ -68,6 +68,10 @@ class FirClassSubstitutionScope(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun processClassifiersByName(name: Name, processor: (FirClassifierSymbol<*>) -> ProcessorAction): ProcessorAction {
|
||||||
|
return useSiteMemberScope.processClassifiersByName(name, processor)
|
||||||
|
}
|
||||||
|
|
||||||
private val typeCalculator by lazy { ReturnTypeCalculatorWithJump(session, scopeSession) }
|
private val typeCalculator by lazy { ReturnTypeCalculatorWithJump(session, scopeSession) }
|
||||||
|
|
||||||
private fun ConeKotlinType.substitute(): ConeKotlinType? {
|
private fun ConeKotlinType.substitute(): ConeKotlinType? {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.scopes.FirOverrideChecker
|
|||||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
@@ -23,6 +24,8 @@ open class FirSuperTypeScope(
|
|||||||
|
|
||||||
private val absentProperties = mutableSetOf<Name>()
|
private val absentProperties = mutableSetOf<Name>()
|
||||||
|
|
||||||
|
private val absentClassifiers = mutableSetOf<Name>()
|
||||||
|
|
||||||
override fun processFunctionsByName(name: Name, processor: (FirFunctionSymbol<*>) -> ProcessorAction): ProcessorAction {
|
override fun processFunctionsByName(name: Name, processor: (FirFunctionSymbol<*>) -> ProcessorAction): ProcessorAction {
|
||||||
if (name in absentFunctions) {
|
if (name in absentFunctions) {
|
||||||
return ProcessorAction.NEXT
|
return ProcessorAction.NEXT
|
||||||
@@ -80,4 +83,33 @@ open class FirSuperTypeScope(
|
|||||||
}
|
}
|
||||||
return super.processPropertiesByName(name, processor)
|
return super.processPropertiesByName(name, processor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun processClassifiersByName(name: Name, processor: (FirClassifierSymbol<*>) -> ProcessorAction): ProcessorAction {
|
||||||
|
if (name in absentClassifiers) {
|
||||||
|
return ProcessorAction.NEXT
|
||||||
|
}
|
||||||
|
val accepted = HashSet<FirClassifierSymbol<*>>()
|
||||||
|
val pending = mutableListOf<FirClassifierSymbol<*>>()
|
||||||
|
var empty = true
|
||||||
|
for (scope in scopes) {
|
||||||
|
if (scope.processClassifiersByName(name) {
|
||||||
|
empty = false
|
||||||
|
if (it !in accepted) {
|
||||||
|
pending += it
|
||||||
|
processor(it)
|
||||||
|
} else {
|
||||||
|
ProcessorAction.NEXT
|
||||||
|
}
|
||||||
|
}.stop()
|
||||||
|
) {
|
||||||
|
return ProcessorAction.STOP
|
||||||
|
}
|
||||||
|
accepted += pending
|
||||||
|
pending.clear()
|
||||||
|
}
|
||||||
|
if (empty) {
|
||||||
|
absentClassifiers += name
|
||||||
|
}
|
||||||
|
return super.processClassifiersByName(name, processor)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+9
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.scopes.impl
|
package org.jetbrains.kotlin.fir.scopes.impl
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.ImplicitReceiverStack
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.calls.ImplicitExtensionReceiverValue
|
||||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol
|
||||||
@@ -12,6 +14,7 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
|
|
||||||
class FirTypeResolveScopeForBodyResolve(
|
class FirTypeResolveScopeForBodyResolve(
|
||||||
private val topLevelScopes: List<FirScope>,
|
private val topLevelScopes: List<FirScope>,
|
||||||
|
private val implicitReceiverStack: ImplicitReceiverStack,
|
||||||
private val localScopes: List<FirScope>
|
private val localScopes: List<FirScope>
|
||||||
) : FirScope() {
|
) : FirScope() {
|
||||||
override fun processClassifiersByName(
|
override fun processClassifiersByName(
|
||||||
@@ -23,6 +26,12 @@ class FirTypeResolveScopeForBodyResolve(
|
|||||||
return ProcessorAction.STOP
|
return ProcessorAction.STOP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (receiverValue in implicitReceiverStack.receiversAsReversed()) {
|
||||||
|
if (receiverValue is ImplicitExtensionReceiverValue) continue
|
||||||
|
if (receiverValue.implicitScope?.processClassifiersByName(name, processor) == ProcessorAction.STOP) {
|
||||||
|
return ProcessorAction.STOP
|
||||||
|
}
|
||||||
|
}
|
||||||
for (scope in topLevelScopes.asReversed()) {
|
for (scope in topLevelScopes.asReversed()) {
|
||||||
if (!scope.processClassifiersByName(name, processor)) {
|
if (!scope.processClassifiersByName(name, processor)) {
|
||||||
return ProcessorAction.STOP
|
return ProcessorAction.STOP
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
abstract class Base {
|
||||||
|
class BaseNested
|
||||||
|
}
|
||||||
|
|
||||||
|
class Derived : Base() {
|
||||||
|
class DerivedNested
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val b: BaseNested = BaseNested()
|
||||||
|
|
||||||
|
val d: DerivedNested = DerivedNested()
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val bb: BaseNested = BaseNested()
|
||||||
|
val dd: DerivedNested = DerivedNested()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
FILE: companionUsesNested.kt
|
||||||
|
public abstract class Base : R|kotlin/Any| {
|
||||||
|
public constructor(): R|Base| {
|
||||||
|
super<R|kotlin/Any|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class BaseNested : R|kotlin/Any| {
|
||||||
|
public constructor(): R|Base.BaseNested| {
|
||||||
|
super<R|kotlin/Any|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public final class Derived : R|Base| {
|
||||||
|
public constructor(): R|Derived| {
|
||||||
|
super<R|Base|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class DerivedNested : R|kotlin/Any| {
|
||||||
|
public constructor(): R|Derived.DerivedNested| {
|
||||||
|
super<R|kotlin/Any|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public final companion object Companion : R|kotlin/Any| {
|
||||||
|
private constructor(): R|Derived.Companion| {
|
||||||
|
super<R|kotlin/Any|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
public final val b: R|Base.BaseNested| = R|/Base.BaseNested.BaseNested|()
|
||||||
|
public get(): R|Base.BaseNested|
|
||||||
|
|
||||||
|
public final val d: R|Derived.DerivedNested| = R|/Derived.DerivedNested.DerivedNested|()
|
||||||
|
public get(): R|Derived.DerivedNested|
|
||||||
|
|
||||||
|
public final fun foo(): R|kotlin/Unit| {
|
||||||
|
lval bb: R|Base.BaseNested| = R|/Base.BaseNested.BaseNested|()
|
||||||
|
lval dd: R|Derived.DerivedNested| = R|/Derived.DerivedNested.DerivedNested|()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+5
@@ -38,6 +38,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
|||||||
runTest("compiler/fir/resolve/testData/resolve/companion.kt");
|
runTest("compiler/fir/resolve/testData/resolve/companion.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("companionUsesNested.kt")
|
||||||
|
public void testCompanionUsesNested() throws Exception {
|
||||||
|
runTest("compiler/fir/resolve/testData/resolve/companionUsesNested.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("copy.kt")
|
@TestMetadata("copy.kt")
|
||||||
public void testCopy() throws Exception {
|
public void testCopy() throws Exception {
|
||||||
runTest("compiler/fir/resolve/testData/resolve/copy.kt");
|
runTest("compiler/fir/resolve/testData/resolve/copy.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user