diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirTowerResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirTowerResolver.kt index ac7db163a2a..4be040cb843 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirTowerResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirTowerResolver.kt @@ -46,7 +46,7 @@ class FirTowerResolver( // } towerDataConsumer.consume( TOWER_LEVEL, - MemberScopeTowerLevel(session, implicitReceiverValue, scopeSession = components.scopeSession), + MemberScopeTowerLevel(session, components, implicitReceiverValue, scopeSession = components.scopeSession), group++ ) @@ -57,7 +57,7 @@ class FirTowerResolver( // } towerDataConsumer.consume( TOWER_LEVEL, - MemberScopeTowerLevel(session, implicitReceiverValue, implicitReceiverValue, components.scopeSession), + MemberScopeTowerLevel(session, components, implicitReceiverValue, implicitReceiverValue, components.scopeSession), group++ ) @@ -127,7 +127,8 @@ class FirTowerResolver( towerDataConsumer.consume( TOWER_LEVEL, MemberScopeTowerLevel( - session, scopeSession = components.scopeSession, + session, components, + scopeSession = components.scopeSession, dispatchReceiver = implicitDispatchReceiverValue, implicitExtensionReceiver = implicitReceiverValue ), diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerDataConsumers.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerDataConsumers.kt index 65584d0bee7..059c2c30e75 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerDataConsumers.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerDataConsumers.kt @@ -171,13 +171,14 @@ class ExplicitReceiverTowerDataConsumer>( if (skipGroup(group, resultCollector)) return ProcessorAction.NEXT return when (kind) { TowerDataKind.EMPTY -> - MemberScopeTowerLevel(session, explicitReceiver, scopeSession = candidateFactory.bodyResolveComponents.scopeSession) - .processElementsByName( - token, - name, - explicitReceiver = null, - processor = EmptyKindTowerProcessor(group) - ) + MemberScopeTowerLevel( + session, resultCollector.components, explicitReceiver, scopeSession = candidateFactory.bodyResolveComponents.scopeSession + ).processElementsByName( + token, + name, + explicitReceiver = null, + processor = EmptyKindTowerProcessor(group) + ) TowerDataKind.TOWER_LEVEL -> { if (token == TowerScopeLevel.Token.Objects) return ProcessorAction.NEXT towerScopeLevel.processElementsByName( diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerLevels.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerLevels.kt index 132480ea9b4..730a580ef14 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerLevels.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerLevels.kt @@ -86,6 +86,7 @@ abstract class SessionBasedTowerLevel(val session: FirSession) : TowerScopeLevel // or given implicit or explicit receiver, otherwise class MemberScopeTowerLevel( session: FirSession, + val bodyResolveComponents: BodyResolveComponents, val dispatchReceiver: ReceiverValue, val implicitExtensionReceiver: ImplicitReceiverValue<*>? = null, val scopeSession: ScopeSession @@ -128,7 +129,7 @@ class MemberScopeTowerLevel( this.processPropertiesByName(name, symbol.cast()) } TowerScopeLevel.Token.Functions -> processMembers(processor, explicitExtensionReceiver) { symbol -> - this.processFunctionsByName(name, symbol.cast()) + this.processFunctionsAndConstructorsByName(name, session, bodyResolveComponents, symbol.cast()) } TowerScopeLevel.Token.Objects -> processMembers(processor, explicitExtensionReceiver) { symbol -> this.processClassifiersByName(name, symbol.cast()) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassDeclaredMemberScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassDeclaredMemberScope.kt index ce7a963b59d..345b08edce5 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassDeclaredMemberScope.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassDeclaredMemberScope.kt @@ -37,13 +37,6 @@ class FirClassDeclaredMemberScope(klass: FirClass<*>, useLazyNestedClassifierSco } result.getOrPut(name) { mutableListOf() } += declaration.symbol } - is FirRegularClass -> { - for (nestedDeclaration in declaration.declarations) { - if (nestedDeclaration is FirConstructor) { - result.getOrPut(declaration.name) { mutableListOf() } += nestedDeclaration.symbol - } - } - } } } result diff --git a/compiler/fir/resolve/testData/resolve/problems/nestedClassContructor.kt b/compiler/fir/resolve/testData/resolve/problems/nestedClassContructor.kt index 6bffdfd41b3..076512e710a 100644 --- a/compiler/fir/resolve/testData/resolve/problems/nestedClassContructor.kt +++ b/compiler/fir/resolve/testData/resolve/problems/nestedClassContructor.kt @@ -2,8 +2,28 @@ * We see same constructor of `B` in two scopes */ -class A() { +open class A() { class B() : A() { - fun copy() = B() + fun copy() = B() + } + + open class C() { + fun copy() = C() + } +} + +class D : A.C() { + fun foo() { + val a = A() + val ac = A.C() + + val c = C() // shouldn't resolve + } +} + +class E : A() { + fun foo() { + val a = A() + val c = C() } } diff --git a/compiler/fir/resolve/testData/resolve/problems/nestedClassContructor.txt b/compiler/fir/resolve/testData/resolve/problems/nestedClassContructor.txt index beb8e3231b7..0c47ccc57b1 100644 --- a/compiler/fir/resolve/testData/resolve/problems/nestedClassContructor.txt +++ b/compiler/fir/resolve/testData/resolve/problems/nestedClassContructor.txt @@ -1,5 +1,5 @@ FILE: nestedClassContructor.kt - public final class A : R|kotlin/Any| { + public open class A : R|kotlin/Any| { public constructor(): R|A| { super() } @@ -9,10 +9,44 @@ FILE: nestedClassContructor.kt super() } - public final fun copy(): { - ^copy #() + public final fun copy(): R|A.B| { + ^copy R|/A.B.B|() + } + + } + + public open class C : R|kotlin/Any| { + public constructor(): R|A.C| { + super() + } + + public final fun copy(): R|A.C| { + ^copy R|/A.C.C|() } } } + public final class D : R|A.C| { + public constructor(): R|D| { + super() + } + + public final fun foo(): R|kotlin/Unit| { + lval a: R|A| = R|/A.A|() + lval ac: R|A.C| = Q|A|.R|/A.C.C|() + lval c: = #() + } + + } + public final class E : R|A| { + public constructor(): R|E| { + super() + } + + public final fun foo(): R|kotlin/Unit| { + lval a: R|A| = R|/A.A|() + lval c: R|A.C| = R|/A.C.C|() + } + + } diff --git a/compiler/testData/ir/irText/expressions/constructorWithOwnTypeParametersCall.fir.txt b/compiler/testData/ir/irText/expressions/constructorWithOwnTypeParametersCall.fir.txt index c47075034cd..68847973cdb 100644 --- a/compiler/testData/ir/irText/expressions/constructorWithOwnTypeParametersCall.fir.txt +++ b/compiler/testData/ir/irText/expressions/constructorWithOwnTypeParametersCall.fir.txt @@ -4,10 +4,11 @@ FILE fqName: fileName:/constructorWithOwnTypeParametersCall.kt RETURN type=kotlin.Nothing from='public final fun testKotlin (): .K1.K2 declared in ' CONSTRUCTOR_CALL 'public constructor () [primary] declared in .K1.K2' type=.K1.K2 origin=null : - FUN name:testJava visibility:public modality:FINAL <> () returnType:IrErrorType + FUN name:testJava visibility:public modality:FINAL <> () returnType:.J1.J2 BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun testJava (): IrErrorType declared in ' - ERROR_CALL 'Unresolved reference: #' type=IrErrorType + RETURN type=kotlin.Nothing from='public final fun testJava (): .J1.J2 declared in ' + CONSTRUCTOR_CALL 'public constructor () declared in .J1.J2' type=.J1.J2 origin=null + : CLASS CLASS name:K1 modality:FINAL visibility:public superTypes:[kotlin.Any] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.K1 TYPE_PARAMETER name:T1 index:0 variance: superTypes:[] diff --git a/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.txt b/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.txt index f641f5393b4..ca7561352b0 100644 --- a/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.txt +++ b/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.txt @@ -10,14 +10,16 @@ FILE fqName: fileName:/javaConstructorWithTypeParameters.kt CONSTRUCTOR_CALL 'public constructor (x1: X1 of ?) declared in .J1' type=.J1 origin=null : x1: CONST Int type=kotlin.Int value=1 - FUN name:test3 visibility:public modality:FINAL <> (j1:.J1) returnType:IrErrorType + FUN name:test3 visibility:public modality:FINAL <> (j1:.J1) returnType:.J1.J2 VALUE_PARAMETER name:j1 index:0 type:.J1 BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test3 (j1: .J1): IrErrorType declared in ' - ERROR_CALL 'Unresolved reference: #' type=IrErrorType - FUN name:test4 visibility:public modality:FINAL <> (j1:.J1) returnType:IrErrorType + RETURN type=kotlin.Nothing from='public final fun test3 (j1: .J1): .J1.J2 declared in ' + CONSTRUCTOR_CALL 'public constructor () declared in .J1.J2' type=.J1.J2 origin=null + : + FUN name:test4 visibility:public modality:FINAL <> (j1:.J1) returnType:.J1.J2 VALUE_PARAMETER name:j1 index:0 type:.J1 BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test4 (j1: .J1): IrErrorType declared in ' - ERROR_CALL 'Unresolved reference: #' type=IrErrorType - CONST Int type=kotlin.Int value=1 + RETURN type=kotlin.Nothing from='public final fun test4 (j1: .J1): .J1.J2 declared in ' + CONSTRUCTOR_CALL 'public constructor (x2: X2 of ?) declared in .J1.J2' type=.J1.J2 origin=null + : + x2: CONST Int type=kotlin.Int value=1