From 9ca71bc93784813b3d96926e24e4b0cf1ea323a2 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 28 Apr 2023 23:52:02 +0200 Subject: [PATCH] fix %option merge not choosing correct block to merge into --- compiler/src/prog8/compiler/ModuleImporter.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/compiler/src/prog8/compiler/ModuleImporter.kt b/compiler/src/prog8/compiler/ModuleImporter.kt index a3384dc35..816d76393 100644 --- a/compiler/src/prog8/compiler/ModuleImporter.kt +++ b/compiler/src/prog8/compiler/ModuleImporter.kt @@ -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() 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) + } } }