From f2cf64aec7a590aa59f37e8ec7f7e39706d386f8 Mon Sep 17 00:00:00 2001 From: Leonid Startsev Date: Wed, 16 Sep 2020 20:32:19 +0300 Subject: [PATCH] Create plugin context before launching actual psi2ir process. Because IrPluginContextImpl constructor creates new instance of BuiltinSymbolsBase (with symbols for stdlib declarations like `arrayOf` etc), there should be at least one pass of `declareUnboundSymbolsAsDependencies` between creation and usage in plugin. Such pass is located between psi2ir and compiler plugins application. If plugin context is created inside lambda, right before plugins are applied, the symbols will remain unbound. #KT-41764 Fixed --- .../jetbrains/kotlin/ir/backend/js/klib.kt | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt b/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt index 05bc49a0205..2539325cf71 100644 --- a/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt +++ b/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt @@ -314,20 +314,22 @@ fun GeneratorContext.generateModuleFragmentWithPlugins( val extensions = IrGenerationExtension.getInstances(project) - for (extension in extensions) { - psi2Ir.addPostprocessingStep { module -> - extension.generate( - module, - IrPluginContextImpl( - moduleDescriptor, - bindingContext, - languageVersionSettings, - symbolTable, - typeTranslator, - irBuiltIns, - linker = irLinker - ) - ) + if (extensions.isNotEmpty()) { + // plugin context should be instantiated before postprocessing steps + val pluginContext = IrPluginContextImpl( + moduleDescriptor, + bindingContext, + languageVersionSettings, + symbolTable, + typeTranslator, + irBuiltIns, + linker = irLinker + ) + + for (extension in extensions) { + psi2Ir.addPostprocessingStep { module -> + extension.generate(module, pluginContext) + } } }