Skip to content

Commit 9982042

Browse files
broadwaylambSpace Team
authored and
Space Team
committed
[Common BE] Don't throw exception for inner classes inside local classes
…that capture a generic parameter. Inner classes inside local classes are not collected by `collectLocalDeclarations` because they are handled later by `InnerClassesLowering` and `InnerClassesMemberBodyLowering`. ^KT-77021 Fixed
1 parent d3e2011 commit 9982042

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt

+5-6
Original file line numberDiff line numberDiff line change
@@ -738,12 +738,11 @@ open class LocalDeclarationsLowering(
738738
}
739739

740740
override fun visitClass(declaration: IrClass, currentLocalClass: LocalClassContext?) {
741-
super.visitClass(
742-
declaration, localClasses[declaration] ?: compilationException(
743-
"Encountered a local class not previously collected",
744-
declaration,
745-
)
746-
)
741+
val newLocalClassContext = localClasses[declaration]
742+
if (newLocalClassContext == null && declaration.isLocalNotInner()) {
743+
compilationException("Encountered a local class not previously collected", declaration)
744+
}
745+
super.visitClass(declaration, newLocalClassContext ?: currentLocalClass)
747746
}
748747

749748
override fun <Type : IrType?> transformTypeRecursively(

compiler/testData/codegen/box/objects/innerClassInsideAnonymousObject.kt

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// ISSUE: KT-77021
2-
// IGNORE_BACKEND: JS_IR, JS_IR_ES6, WASM, NATIVE
32

43
class Generic<T>(val t: T) {
54
fun foo(): T {

0 commit comments

Comments
 (0)