Fir2Ir: handle nested class references in type parameter bounds

This commit is contained in:
Georgy Bronnikov
2022-04-23 20:07:06 +03:00
committed by Alexander Udalov
parent 9fb1a901cf
commit 49576e0cbb
8 changed files with 50 additions and 0 deletions
@@ -546,6 +546,10 @@ class Fir2IrClassifierStorage(
val parentId = classId.outerClassId
val parentClass = parentId?.let { session.symbolProvider.getClassLikeSymbolByClassId(it) }
val irParent = declarationStorage.findIrParent(classId.packageFqName, parentClass?.toLookupTag(), firClassSymbol, firClass.origin)!!
// firClass may be referenced by some parent's type parameters as a bound. In that case, getIrClassSymbol will be called recursively.
getCachedIrClass(firClass)?.let { return it.symbol }
val irClass = firClass.convertWithOffsets { startOffset, endOffset ->
symbolTable.declareClass(signature, { symbol }) {
Fir2IrLazyClass(components, startOffset, endOffset, firClass.irOrigin(firProvider), firClass, symbol).apply {
@@ -7355,6 +7355,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/nestedClass.kt");
}
@Test
@TestMetadata("nestedClassAsBound.kt")
public void testNestedClassAsBound() throws Exception {
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/nestedClassAsBound.kt");
}
@Test
@TestMetadata("nestedClassInAnnotationArgument.kt")
public void testNestedClassInAnnotationArgument() throws Exception {
@@ -0,0 +1,10 @@
// MODULE: lib
// FILE: Q.kt
class Q<T : Q.S> {
open class S {
val ok = "OK"
}
}
// MODULE: main(lib)
// FILE: box.kt
fun box() = Q.S().ok
@@ -7241,6 +7241,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/nestedClass.kt");
}
@Test
@TestMetadata("nestedClassAsBound.kt")
public void testNestedClassAsBound() throws Exception {
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/nestedClassAsBound.kt");
}
@Test
@TestMetadata("nestedClassInAnnotationArgument.kt")
public void testNestedClassInAnnotationArgument() throws Exception {
@@ -7355,6 +7355,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/nestedClass.kt");
}
@Test
@TestMetadata("nestedClassAsBound.kt")
public void testNestedClassAsBound() throws Exception {
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/nestedClassAsBound.kt");
}
@Test
@TestMetadata("nestedClassInAnnotationArgument.kt")
public void testNestedClassInAnnotationArgument() throws Exception {
@@ -337,6 +337,12 @@ public class JvmIrAgainstOldBoxTestGenerated extends AbstractJvmIrAgainstOldBoxT
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/nestedClass.kt");
}
@Test
@TestMetadata("nestedClassAsBound.kt")
public void testNestedClassAsBound() throws Exception {
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/nestedClassAsBound.kt");
}
@Test
@TestMetadata("nestedClassInAnnotationArgument.kt")
public void testNestedClassInAnnotationArgument() throws Exception {
@@ -337,6 +337,12 @@ public class JvmOldAgainstIrBoxTestGenerated extends AbstractJvmOldAgainstIrBoxT
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/nestedClass.kt");
}
@Test
@TestMetadata("nestedClassAsBound.kt")
public void testNestedClassAsBound() throws Exception {
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/nestedClassAsBound.kt");
}
@Test
@TestMetadata("nestedClassInAnnotationArgument.kt")
public void testNestedClassInAnnotationArgument() throws Exception {