diff --git a/compiler/fir/analysis-tests/testData/resolve/objectInnerClass.kt b/compiler/fir/analysis-tests/testData/resolve/objectInnerClass.kt index 473fbc09289..22b8198f232 100644 --- a/compiler/fir/analysis-tests/testData/resolve/objectInnerClass.kt +++ b/compiler/fir/analysis-tests/testData/resolve/objectInnerClass.kt @@ -7,22 +7,22 @@ val case1 = object : A { inner class Child(property: B) : Base(property) { fun Base.zoo() { - val x = property //UNRESOLVED_REFERENCE + val x = property } fun foo() { - baseFun() //UNRESOLVED_REFERENCE - val x = property //UNRESOLVED_REFERENCE - zoo() //UNRESOLVED_REFERENCE + baseFun() + val x = property + zoo() hoo() } } - fun Child.voo() { - val x = property //UNRESOLVED_REFERENCE + fun Child.voo() { + val x = property } - fun Base.hoo() { - val x = property //UNRESOLVED_REFERENCE + fun Base.hoo() { + val x = property } open inner class Base(/*protected*/ val property: B) { @@ -32,8 +32,8 @@ val case1 = object : A { fun caseForBase() { val base = Base(B()) /*member of Base*/ - base.baseFun() //UNRESOLVED_REFERENCE - base.property //UNRESOLVED_REFERENCE + base.baseFun() + base.property /*extensions*/ base.hoo() } @@ -41,10 +41,10 @@ val case1 = object : A { fun caseForChild() { val child = Child(B()) /*member of Base*/ - child.baseFun() //UNRESOLVED_REFERENCE - child.property //UNRESOLVED_REFERENCE + child.baseFun() + child.property /*member of Child*/ - child.foo() //UNRESOLVED_REFERENCE + child.foo() /*extensions*/ child.hoo() child.voo() @@ -100,22 +100,22 @@ class Case3() { val x = object : A { inner class Child(property: B) : Base(property) { fun Base.zoo() { - val x = property //UNRESOLVED_REFERENCE + val x = property } fun foo() { - baseFun() //UNRESOLVED_REFERENCE - val x = property //UNRESOLVED_REFERENCE - zoo() + baseFun() + val x = property + zoo() hoo() } } - fun Child.voo() { - val x = property //UNRESOLVED_REFERENCE + fun Child.voo() { + val x = property } - fun Base.hoo() { - val x = property //UNRESOLVED_REFERENCE + fun Base.hoo() { + val x = property } open inner class Base(/*protected*/ val property: B) { @@ -125,8 +125,8 @@ class Case3() { fun caseForBase() { val base = Base(B()) /*member of Base*/ - base.baseFun() //UNRESOLVED_REFERENCE - base.property //UNRESOLVED_REFERENCE + base.baseFun() + base.property /*extensions*/ base.hoo() } @@ -134,10 +134,10 @@ class Case3() { fun caseForChild() { val child = Child(B()) /*member of Base*/ - child.baseFun() //UNRESOLVED_REFERENCE - child.property //UNRESOLVED_REFERENCE + child.baseFun() + child.property /*member of Child*/ - child.foo() //UNRESOLVED_REFERENCE + child.foo() /*extensions*/ child.hoo() child.voo() diff --git a/compiler/fir/analysis-tests/testData/resolve/objectInnerClass.txt b/compiler/fir/analysis-tests/testData/resolve/objectInnerClass.txt index 1b26e3bd6db..5007adee213 100644 --- a/compiler/fir/analysis-tests/testData/resolve/objectInnerClass.txt +++ b/compiler/fir/analysis-tests/testData/resolve/objectInnerClass.txt @@ -4,30 +4,30 @@ FILE: objectInnerClass.kt super() } - local final inner class Child : R|ERROR CLASS: Symbol not found, for `Base`| { + local final inner class Child : R|.Base| { public[local] constructor(property: R|B|): R|.Child| { - super(R|/property|) + super.Base|>(R|/property|) } - public[local] final fun R|ERROR CLASS: Symbol not found, for `Base`|.zoo(): R|kotlin/Unit| { - lval x: = # + public[local] final fun R|.Base|.zoo(): R|kotlin/Unit| { + lval x: R|B| = this@R|/.Child.zoo|.R|/.Base.property| } public[local] final fun foo(): R|kotlin/Unit| { - #() - lval x: = # - #() + this@R|/.Child|.R|/.Base.baseFun|() + lval x: R|B| = this@R|/.Child|.R|/.Base.property| + (this@R|/.Child|, this@R|/.Child|).R|/.Child.zoo|() (this@R|/anonymous|, this@R|/.Child|).R|/anonymous.hoo|() } } - public final fun R|ERROR CLASS: Symbol not found, for `Child`|.voo(): R|kotlin/Unit| { - lval x: = # + public final fun R|.Child|.voo(): R|kotlin/Unit| { + lval x: R|B| = this@R|/anonymous.voo|.R|/.Base.property| } - public final fun R|ERROR CLASS: Symbol not found, for `Base`|.hoo(): R|kotlin/Unit| { - lval x: = # + public final fun R|.Base|.hoo(): R|kotlin/Unit| { + lval x: R|B| = this@R|/anonymous.hoo|.R|/.Base.property| } local open inner class Base : R|kotlin/Any| { @@ -45,16 +45,16 @@ FILE: objectInnerClass.kt public final fun caseForBase(): R|kotlin/Unit| { lval base: R|.Base| = this@R|/anonymous|.R|/.Base.Base|(R|/B.B|()) - R|/base|.#() - R|/base|.# + R|/base|.R|/.Base.baseFun|() + R|/base|.R|/.Base.property| (this@R|/anonymous|, R|/base|).R|/anonymous.hoo|() } public final fun caseForChild(): R|kotlin/Unit| { lval child: R|.Child| = this@R|/anonymous|.R|/.Child.Child|(R|/B.B|()) - R|/child|.#() - R|/child|.# - R|/child|.#() + R|/child|.R|/.Base.baseFun|() + R|/child|.R|/.Base.property| + R|/child|.R|/.Child.foo|() (this@R|/anonymous|, R|/child|).R|/anonymous.hoo|() (this@R|/anonymous|, R|/child|).R|/anonymous.voo|() } @@ -129,30 +129,30 @@ FILE: objectInnerClass.kt super() } - local final inner class Child : R|ERROR CLASS: Symbol not found, for `Base`| { + local final inner class Child : R|Case3..Base| { public[local] constructor(property: R|B|): R|Case3..Child| { - super(R|/property|) + super.Base|>(R|/property|) } - public[local] final fun R|ERROR CLASS: Symbol not found, for `Base`|.zoo(): R|kotlin/Unit| { - lval x: = # + public[local] final fun R|Case3..Base|.zoo(): R|kotlin/Unit| { + lval x: R|B| = this@R|/Case3..Child.zoo|.R|/Case3..Base.property| } public[local] final fun foo(): R|kotlin/Unit| { - #() - lval x: = # - #() + this@R|/Case3..Child|.R|/Case3..Base.baseFun|() + lval x: R|B| = this@R|/Case3..Child|.R|/Case3..Base.property| + (this@R|/Case3..Child|, this@R|/Case3..Child|).R|/Case3..Child.zoo|() (this@R|/anonymous|, this@R|/Case3..Child|).R|/anonymous.hoo|() } } - public final fun R|ERROR CLASS: Symbol not found, for `Child`|.voo(): R|kotlin/Unit| { - lval x: = # + public final fun R|Case3..Child|.voo(): R|kotlin/Unit| { + lval x: R|B| = this@R|/anonymous.voo|.R|/Case3..Base.property| } - public final fun R|ERROR CLASS: Symbol not found, for `Base`|.hoo(): R|kotlin/Unit| { - lval x: = # + public final fun R|Case3..Base|.hoo(): R|kotlin/Unit| { + lval x: R|B| = this@R|/anonymous.hoo|.R|/Case3..Base.property| } local open inner class Base : R|kotlin/Any| { @@ -170,16 +170,16 @@ FILE: objectInnerClass.kt public final fun caseForBase(): R|kotlin/Unit| { lval base: R|Case3..Base| = R|/Case3..Base.Base|(R|/B.B|()) - R|/base|.#() - R|/base|.# + R|/base|.R|/Case3..Base.baseFun|() + R|/base|.R|/Case3..Base.property| (this@R|/anonymous|, R|/base|).R|/anonymous.hoo|() } public final fun caseForChild(): R|kotlin/Unit| { lval child: R|Case3..Child| = R|/Case3..Child.Child|(R|/B.B|()) - R|/child|.#() - R|/child|.# - R|/child|.#() + R|/child|.R|/Case3..Base.baseFun|() + R|/child|.R|/Case3..Base.property| + R|/child|.R|/Case3..Child.foo|() (this@R|/anonymous|, R|/child|).R|/anonymous.hoo|() (this@R|/anonymous|, R|/child|).R|/anonymous.voo|() } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAbstractTreeTransformerWithSuperTypes.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAbstractTreeTransformerWithSuperTypes.kt index 744b75c9f43..960e3c14e76 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAbstractTreeTransformerWithSuperTypes.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAbstractTreeTransformerWithSuperTypes.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.fir.resolve.transformers +import org.jetbrains.kotlin.fir.declarations.FirClass import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.declarations.FirResolvePhase @@ -32,25 +33,28 @@ abstract class FirAbstractTreeTransformerWithSuperTypes( } protected fun resolveNestedClassesSupertypes( - regularClass: FirRegularClass, + firClass: FirClass<*>, data: Nothing? ): CompositeTransformResult { return withScopeCleanup { // ? Is it Ok to use original file session here ? - val superTypes = lookupSuperTypes(regularClass, lookupInterfaces = false, deep = true, useSiteSession = session).asReversed() + val superTypes = lookupSuperTypes(firClass, lookupInterfaces = false, deep = true, useSiteSession = session).asReversed() for (superType in superTypes) { session.getNestedClassifierScope(superType.lookupTag)?.let { towerScope.addScope(it) } } - regularClass.addTypeParametersScope() - val companionObject = regularClass.companionObject - if (companionObject != null) { - towerScope.addScope(nestedClassifierScope(companionObject)) + if (firClass is FirRegularClass) { + firClass.addTypeParametersScope() + val companionObject = firClass.companionObject + if (companionObject != null) { + towerScope.addScope(nestedClassifierScope(companionObject)) + } } - towerScope.addScope(nestedClassifierScope(regularClass)) - transformElement(regularClass, data) + towerScope.addScope(nestedClassifierScope(firClass)) + + transformElement(firClass, data) } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt index a00559ecf57..c4ec6618711 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt @@ -77,6 +77,10 @@ private class FirTypeResolveTransformer( return resolveNestedClassesSupertypes(regularClass, data) } + override fun transformAnonymousObject(anonymousObject: FirAnonymousObject, data: Nothing?): CompositeTransformResult { + return resolveNestedClassesSupertypes(anonymousObject, data) + } + override fun transformConstructor(constructor: FirConstructor, data: Nothing?): CompositeTransformResult { return withScopeCleanup { constructor.addTypeParametersScope() diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromOuterClassInObjectLiteral.fir.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromOuterClassInObjectLiteral.fir.kt new file mode 100644 index 00000000000..8a526465da1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromOuterClassInObjectLiteral.fir.kt @@ -0,0 +1,15 @@ +class A { + fun foo() { + val q = object { + open inner class B + inner class C : B() + + // No WRONG_NUMBER_OF_TYPE_ARGUMENTS should be reported on these types + val x: B = B() + val y: C = C() + } + + q.x + q.y + } +} diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromOuterClassInObjectLiteral.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromOuterClassInObjectLiteral.kt index 470b1d33a08..22600b275a6 100644 --- a/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromOuterClassInObjectLiteral.kt +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/implicitArguments/fromOuterClassInObjectLiteral.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL class A { fun foo() { val q = object {