fix %option merge not choosing correct block to merge into

This commit is contained in:
Irmen de Jong 2023-04-28 23:52:02 +02:00
parent 5407429ec0
commit 9ca71bc937

View File

@ -106,13 +106,15 @@ class ModuleImporter(private val program: Program,
removeDirectivesFromImportedModule(importedModule)
// modules can contain blocks with "merge" option.
// their content has to be merged into already existing block with the same name.
// their content has to be merged into already existing other block with the same name.
val blocks = importedModule.statements.filterIsInstance<Block>()
for(block in blocks) {
if("merge" in block.options()) {
val existingBlock = program.allBlocks.first { it.name==block.name}
existingBlock.statements.addAll(block.statements.filter { it !is Directive})
importedModule.statements.remove(block)
val existingBlock = program.allBlocks.firstOrNull { it.name==block.name && it !== block}
if(existingBlock!=null) {
existingBlock.statements.addAll(block.statements.filter { it !is Directive })
importedModule.statements.remove(block)
}
}
}