From c15805f721a28bf4f52fa797a7a362fb907bf696 Mon Sep 17 00:00:00 2001 From: clararod9 Date: Thu, 2 Jun 2022 12:56:03 +0200 Subject: [PATCH] fixing bug in conditional creation of components inside loops --- compiler/src/hir/component_preprocess.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/compiler/src/hir/component_preprocess.rs b/compiler/src/hir/component_preprocess.rs index 2411249..5ef5474 100644 --- a/compiler/src/hir/component_preprocess.rs +++ b/compiler/src/hir/component_preprocess.rs @@ -16,7 +16,10 @@ fn rm_statement(stmt: &mut Statement) { rm_block(stmt); } else if stmt.is_initialization_block() { rm_init(stmt); - } else { + } else if stmt.is_substitution(){ + rm_substitution(stmt); + } + else{ } } @@ -73,6 +76,15 @@ fn rm_init(stmt: &mut Statement) { } } +fn rm_substitution(stmt: &mut Statement){ + use Statement::{Block, Substitution}; + if should_be_removed(stmt){ + if let Substitution { meta, .. } = stmt{ + *stmt = Block{ meta: meta.clone(), stmts: Vec::new() }; + } + } +} + fn should_be_removed(stmt: &Statement) -> bool { use Statement::{InitializationBlock, Substitution}; use VariableType::*;