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)
|
||||
}
|
||||
|
||||
override fun processClassifiersByName(name: Name, processor: (FirClassifierSymbol<*>) -> ProcessorAction): ProcessorAction {
|
||||
return useSiteMemberScope.processClassifiersByName(name, processor)
|
||||
}
|
||||
|
||||
private fun enhance(
|
||||
original: FirCallableSymbol<*>,
|
||||
name: Name
|
||||
|
||||
+14
@@ -53,6 +53,7 @@ class ConeOverloadConflictResolver(
|
||||
is FirSimpleFunction -> createFlatSignature(call, declaration)
|
||||
is FirConstructor -> createFlatSignature(call, declaration)
|
||||
is FirVariable<*> -> createFlatSignature(call, declaration)
|
||||
is FirClass<*> -> createFlatSignature(call, 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 {
|
||||
return ConeSimpleConstraintSystemImpl(inferenceComponents.createConstraintSystem())
|
||||
}
|
||||
|
||||
+1
-1
@@ -117,7 +117,7 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb
|
||||
qualifiedResolver
|
||||
)
|
||||
val typeResolverTransformer = FirSpecificTypeResolverTransformer(
|
||||
FirTypeResolveScopeForBodyResolve(topLevelScopes, localScopes), session
|
||||
FirTypeResolveScopeForBodyResolve(topLevelScopes, implicitReceiverStack, localScopes), session
|
||||
)
|
||||
val callCompleter: FirCallCompleter = FirCallCompleter(transformer, 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.scopes.impl.FirLocalScope
|
||||
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.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirComputingImplicitTypeRef
|
||||
@@ -229,11 +228,6 @@ class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransformer)
|
||||
if (regularClass.symbol.classId.isLocal) {
|
||||
prepareLocalClassForBodyResolve(regularClass)
|
||||
}
|
||||
val companionObject = regularClass.companionObject
|
||||
if (companionObject != null) {
|
||||
topLevelScopes += nestedClassifierScope(companionObject)
|
||||
}
|
||||
topLevelScopes += nestedClassifierScope(regularClass)
|
||||
|
||||
val oldConstructorScope = primaryConstructorParametersScope
|
||||
val oldContainingClass = containingClass
|
||||
@@ -258,8 +252,6 @@ class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransformer)
|
||||
override fun transformAnonymousObject(anonymousObject: FirAnonymousObject, data: ResolutionMode): CompositeTransformResult<FirStatement> {
|
||||
prepareLocalClassForBodyResolve(anonymousObject)
|
||||
return withScopeCleanup(topLevelScopes) {
|
||||
topLevelScopes += nestedClassifierScope(anonymousObject)
|
||||
|
||||
val type = anonymousObject.defaultType()
|
||||
anonymousObject.resultType = FirResolvedTypeRefImpl(anonymousObject.source, type)
|
||||
val result = withLabelAndReceiverType(null, anonymousObject, type) {
|
||||
|
||||
+4
-1
@@ -42,6 +42,9 @@ abstract class AbstractFirUseSiteMemberScope(
|
||||
name: Name,
|
||||
processor: (FirClassifierSymbol<*>) -> 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 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.ProcessorAction
|
||||
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.name.Name
|
||||
|
||||
@@ -23,6 +24,8 @@ open class FirSuperTypeScope(
|
||||
|
||||
private val absentProperties = mutableSetOf<Name>()
|
||||
|
||||
private val absentClassifiers = mutableSetOf<Name>()
|
||||
|
||||
override fun processFunctionsByName(name: Name, processor: (FirFunctionSymbol<*>) -> ProcessorAction): ProcessorAction {
|
||||
if (name in absentFunctions) {
|
||||
return ProcessorAction.NEXT
|
||||
@@ -80,4 +83,33 @@ open class FirSuperTypeScope(
|
||||
}
|
||||
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
|
||||
|
||||
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.ProcessorAction
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol
|
||||
@@ -12,6 +14,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirTypeResolveScopeForBodyResolve(
|
||||
private val topLevelScopes: List<FirScope>,
|
||||
private val implicitReceiverStack: ImplicitReceiverStack,
|
||||
private val localScopes: List<FirScope>
|
||||
) : FirScope() {
|
||||
override fun processClassifiersByName(
|
||||
@@ -23,6 +26,12 @@ class FirTypeResolveScopeForBodyResolve(
|
||||
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()) {
|
||||
if (!scope.processClassifiersByName(name, processor)) {
|
||||
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");
|
||||
}
|
||||
|
||||
@TestMetadata("companionUsesNested.kt")
|
||||
public void testCompanionUsesNested() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/companionUsesNested.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("copy.kt")
|
||||
public void testCopy() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/copy.kt");
|
||||
|
||||
Reference in New Issue
Block a user