diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt index f0d695d6c37..5db04ec4ed7 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.declarations.FirClass import org.jetbrains.kotlin.fir.declarations.FirResolvePhase import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression import org.jetbrains.kotlin.fir.resolve.substitution.ConeRawScopeSubstitutor +import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap import org.jetbrains.kotlin.fir.scopes.* import org.jetbrains.kotlin.fir.scopes.impl.FirScopeWithCallableCopyReturnTypeUpdater @@ -57,9 +58,23 @@ fun FirSmartCastExpression.smartcastScope( fun ConeClassLikeType.delegatingConstructorScope( useSiteSession: FirSession, scopeSession: ScopeSession, - derivedClassLookupTag: ConeClassLikeLookupTag + derivedClassLookupTag: ConeClassLikeLookupTag, + outerType: ConeClassLikeType? ): FirTypeScope? { - return classScope(useSiteSession, scopeSession, FirResolvePhase.DECLARATIONS, derivedClassLookupTag) + val fir = fullyExpandedType(useSiteSession).lookupTag.toSymbol(useSiteSession)?.fir as? FirClass ?: return null + + val substitutor = when { + outerType != null -> { + val outerFir = outerType.lookupTag.toSymbol(useSiteSession)?.fir as? FirClass ?: return null + substitutorByMap( + createSubstitutionForScope(outerFir.typeParameters, outerType, useSiteSession), + useSiteSession, + ) + } + else -> ConeSubstitutor.Empty + } + + return fir.scopeForClass(substitutor, useSiteSession, scopeSession, derivedClassLookupTag, FirResolvePhase.DECLARATIONS) } fun ConeKotlinType.scope( diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolver.kt index 28b3e12bd46..3e7db07f790 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolver.kt @@ -95,8 +95,9 @@ class FirTowerResolver( context: ResolutionContext ): CandidateCollector { val outerType = components.outerClassManager.outerType(constructedType) - val scope = constructedType.delegatingConstructorScope(components.session, components.scopeSession, derivedClassLookupTag) - ?: return collector + val scope = + constructedType.delegatingConstructorScope(components.session, components.scopeSession, derivedClassLookupTag, outerType) + ?: return collector val dispatchReceiver = if (outerType != null) diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt41386.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt41386.fir.kt deleted file mode 100644 index dda9447708f..00000000000 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt41386.fir.kt +++ /dev/null @@ -1,6 +0,0 @@ -open class Test(val map1 : Map, val map2 : Map) { - open val inverse: Test = object : Test(map2, map1) { - override val inverse: Test - get() = this@Test - } -} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt41386.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt41386.kt index df7220a83b7..e4dcfd418db 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt41386.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt41386.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL open class Test(val map1 : Map, val map2 : Map) { open val inverse: Test = object : Test(map2, map1) { override val inverse: Test diff --git a/compiler/testData/diagnostics/tests/inner/callingOuterGenericClassConstructorWithSelfTypes.fir.kt b/compiler/testData/diagnostics/tests/inner/callingOuterGenericClassConstructorWithSelfTypes.fir.kt deleted file mode 100644 index 86d8886771e..00000000000 --- a/compiler/testData/diagnostics/tests/inner/callingOuterGenericClassConstructorWithSelfTypes.fir.kt +++ /dev/null @@ -1,21 +0,0 @@ -// ISSUE: KT-64841 - -open class A>(a: Any?) { - // Constraints while resolving super constructor call - // - // The signature of constructor comes substituted - // constructor>|>(a: R|kotlin/Any?|): R|A>| - // - // Xv <: A.B> (from type parameter bounds, actually it's the incorrect place) - // - // Xv := A.B (from explicit type argument of constructor call) - // A.B> <: A.B> - // A.B> <: A.B> - // Xv := X - // X != A.B -> FAIL - inner class B : A("") { - fun foo() { - A("") - } - } -} diff --git a/compiler/testData/diagnostics/tests/inner/callingOuterGenericClassConstructorWithSelfTypes.kt b/compiler/testData/diagnostics/tests/inner/callingOuterGenericClassConstructorWithSelfTypes.kt index d5589237fe0..df99e48f5f5 100644 --- a/compiler/testData/diagnostics/tests/inner/callingOuterGenericClassConstructorWithSelfTypes.kt +++ b/compiler/testData/diagnostics/tests/inner/callingOuterGenericClassConstructorWithSelfTypes.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // ISSUE: KT-64841 open class A>(a: Any?) { diff --git a/compiler/testData/diagnostics/tests/inner/callingOuterGenericClassConstructorWithSelfTypesInitial.fir.kt b/compiler/testData/diagnostics/tests/inner/callingOuterGenericClassConstructorWithSelfTypesInitial.fir.kt deleted file mode 100644 index 426a6b0c392..00000000000 --- a/compiler/testData/diagnostics/tests/inner/callingOuterGenericClassConstructorWithSelfTypesInitial.fir.kt +++ /dev/null @@ -1,6 +0,0 @@ -// ISSUE: KT-64841 -abstract class A> - -abstract class B>(delegate: A) : A() { - inner class C : B>(this) -} diff --git a/compiler/testData/diagnostics/tests/inner/callingOuterGenericClassConstructorWithSelfTypesInitial.kt b/compiler/testData/diagnostics/tests/inner/callingOuterGenericClassConstructorWithSelfTypesInitial.kt index 0e022bf61d0..16d069d25d1 100644 --- a/compiler/testData/diagnostics/tests/inner/callingOuterGenericClassConstructorWithSelfTypesInitial.kt +++ b/compiler/testData/diagnostics/tests/inner/callingOuterGenericClassConstructorWithSelfTypesInitial.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // ISSUE: KT-64841 abstract class A> diff --git a/compiler/testData/diagnostics/tests/j+k/genericConstructor/superCallImpossibleToInfer.fir.kt b/compiler/testData/diagnostics/tests/j+k/genericConstructor/superCallImpossibleToInfer.fir.kt index 81b79c2af59..fdf43a3146f 100644 --- a/compiler/testData/diagnostics/tests/j+k/genericConstructor/superCallImpossibleToInfer.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/genericConstructor/superCallImpossibleToInfer.fir.kt @@ -11,10 +11,10 @@ public class A { // TODO: It's effectively impossible to perform super call to such constructor // if there is not enough information to infer corresponding arguments // May be we could add some special syntax for such arguments -class B1(x: List) : A("", x) +class B1(x: List) : A("", x) class B2(x: List) : A("", x) class C : A { - constructor(x: List) : super("", x) + constructor(x: List) : super("", x) constructor(x: List, y: Int) : super("", x) } diff --git a/compiler/testData/diagnostics/tests/override/derivedClasses/DelegatedConstructor.fir.kt b/compiler/testData/diagnostics/tests/override/derivedClasses/DelegatedConstructor.fir.kt index da4162ac56a..58e8aa7b81f 100644 --- a/compiler/testData/diagnostics/tests/override/derivedClasses/DelegatedConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/override/derivedClasses/DelegatedConstructor.fir.kt @@ -1,3 +1,3 @@ open class Foo(val item: T) -class Bar(str: String) : Foo(str) +class Bar(str: String) : Foo(str)