FIR resolve: add nested companion scope #KT-24095 Fixed
This commit is contained in:
+6
@@ -70,6 +70,12 @@ open class FirTypeResolveTransformer : FirTransformer<Nothing?>() {
|
||||
resolveSuperTypesAndExpansions(klass)
|
||||
|
||||
scope.scopes += FirNestedClassifierScope(classId, klass.session)
|
||||
val companionObjects = klass.declarations.filterIsInstance<FirClass>().filter { it.isCompanion }
|
||||
for (companionObject in companionObjects) {
|
||||
val companionId = ClassId(packageFqName, classLikeName.child(companionObject.name), false)
|
||||
scope.scopes += FirNestedClassifierScope(companionId, klass.session)
|
||||
}
|
||||
|
||||
val superTypeScopes = lookupSuperTypes(klass).map { FirNestedClassifierScope(it, klass.session) }
|
||||
scope.scopes.addAll(superTypeScopes)
|
||||
val result = super.transformClass(klass, data)
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package test
|
||||
|
||||
abstract class Some {
|
||||
companion object {
|
||||
class InCompanion
|
||||
}
|
||||
|
||||
abstract val x: InCompanion
|
||||
}
|
||||
|
||||
abstract class Another {
|
||||
companion object NamedCompanion {
|
||||
class InCompanion
|
||||
}
|
||||
|
||||
abstract val x: InCompanion
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
FILE: companion.kt
|
||||
public? abstract class Some {
|
||||
public? final companion object Companion {
|
||||
public? final class InCompanion {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public? abstract property x(val): R|test/Some.Companion.InCompanion|
|
||||
public? get(): R|test/Some.Companion.InCompanion|
|
||||
|
||||
}
|
||||
public? abstract class Another {
|
||||
public? final companion object NamedCompanion {
|
||||
public? final class InCompanion {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public? abstract property x(val): R|test/Another.NamedCompanion.InCompanion|
|
||||
public? get(): R|test/Another.NamedCompanion.InCompanion|
|
||||
|
||||
}
|
||||
@@ -29,6 +29,12 @@ public class FirResolveTestCaseGenerated extends AbstractFirResolveTestCase {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/fir/resolve"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true, "stdlib");
|
||||
}
|
||||
|
||||
@TestMetadata("companion.kt")
|
||||
public void testCompanion() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/fir/resolve/companion.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("derivedClass.kt")
|
||||
public void testDerivedClass() throws Exception {
|
||||
runTest("compiler/testData/fir/resolve/derivedClass.kt");
|
||||
|
||||
Reference in New Issue
Block a user