From 1c3c5417ad72b508e43d7dda190a3978516e98a3 Mon Sep 17 00:00:00 2001 From: Marco Pennekamp Date: Tue, 31 Jan 2023 20:15:32 +0100 Subject: [PATCH] [JVM IR] KTIJ-24335 Fix stub generation of symbols without descriptors - Symbols without a descriptor (e.g. `IrClassPublicSymbolImpl`) were causing exceptions in `DeclarationStubGenerator` after recent changes, because their property `irClassSymbol.descriptor` doesn't necessarily exist without the symbol having an owner bound to it first. - `DeclarationStubGenerator` now falls back to its `descriptor` argument if `irClassSymbol` doesn't have a descriptor. --- .../jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt index eb203f6a2ef..5a15c88a7cd 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt @@ -263,7 +263,11 @@ abstract class DeclarationStubGenerator( // return a built-in symbol that hasn't been bound yet (e.g. `OptIn`). If the stub generator calls `declareClass` with the incorrect // `descriptor`, a symbol created for `descriptor` will be bound, not the built-in symbol which should be. If `generateClassStub` is // called twice for such a `descriptor`, an exception will occur because `descriptor`'s symbol will already have been bound. - with(irClassSymbol.descriptor) { + // + // Note as well that not all symbols have descriptors. For example, `irClassSymbol` might be an `IrClassPublicSymbolImpl` without a + // descriptor. For such symbols, the `descriptor` argument needs to be used. + val targetDescriptor = if (irClassSymbol.hasDescriptor) irClassSymbol.descriptor else descriptor + with(targetDescriptor) { val origin = computeOrigin(this) return symbolTable.declareClass(this) { IrLazyClass(