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
This commit is contained in:
Leonid Startsev
2020-09-16 20:32:19 +03:00
parent ee3ada4e55
commit f2cf64aec7
@@ -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)
}
}
}