From b88ce50500dd0c7c007d7ab569f515488d1f34f1 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 23 Feb 2024 16:54:57 +0100 Subject: [PATCH] IR: do not visit function body at all in IrFakeOverrideBuilder This change fixes FIR tests with JVM IR serialization enabled, some of which start to fail after enabling IR fake override builder mode by default. In this case, even accessing the function body with `IrFunction.body` does not work in some cases because it tries to load IR and ends up with unbound symbols for some reason (most likely related to KT-63509). So we avoid accessing the body by copying the `IrFunction.acceptChildren` implementation and removing the `body.accept` call. Using deep-copy to create a fake override is questionable here, but it will need to be refactored separately. --- .../overrides/CopyIrTreeWithSymbolsForFakeOverrides.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/overrides/CopyIrTreeWithSymbolsForFakeOverrides.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/overrides/CopyIrTreeWithSymbolsForFakeOverrides.kt index 8bf20b72914..95523cc1563 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/overrides/CopyIrTreeWithSymbolsForFakeOverrides.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/overrides/CopyIrTreeWithSymbolsForFakeOverrides.kt @@ -110,6 +110,16 @@ class CopyIrTreeWithSymbolsForFakeOverrides( override fun visitBlockBody(body: IrBlockBody) {} // don't visit function body and parameter default values override fun visitExpressionBody(body: IrExpressionBody) {} // don't visit function body and parameter default values + override fun visitSimpleFunction(declaration: IrSimpleFunction, data: Nothing?) { + // In case of FIR tests with JVM IR serialization enabled, even accessing the function body with `IrFunction.body` does not work + // in some cases because it tries to load IR and ends up with unbound symbols for some reason (most likely related to KT-63509). + // So we avoid accessing the body by copying the `IrFunction.acceptChildren` implementation and removing the `body.accept` call. + declaration.typeParameters.forEach { it.accept(this, data) } + declaration.dispatchReceiverParameter?.accept(this, data) + declaration.extensionReceiverParameter?.accept(this, data) + declaration.valueParameters.forEach { it.accept(this, data) } + } + override fun getReferencedClassifier(symbol: IrClassifierSymbol): IrClassifierSymbol { val result = super.getReferencedClassifier(symbol) if (result !is IrTypeParameterSymbol)