Skip to content

Commit 681d938

Browse files
committed
feat(analyzer)!: reject mutable dynamic for bounds
1 parent b22fb96 commit 681d938

6 files changed

Lines changed: 1067 additions & 0 deletions

File tree

crates/analyzer/src/analyzer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::attribute_table;
33
use crate::comb_loop_detect;
44
use crate::conv::{Context, Conv};
55
use crate::definition_table;
6+
use crate::dynamic_for_check;
67
use crate::generic_inference_table;
78
use crate::handlers::*;
89
use crate::ir::{Ir, IrResult};
@@ -266,6 +267,7 @@ impl Analyzer {
266267

267268
ret.append(&mut symbol_table::check_unused_variable());
268269
ret.append(&mut symbol_table::check_wavedrom());
270+
ret.append(&mut dynamic_for_check::check(ir));
269271
ret.append(&mut comb_loop_detect::check(ir));
270272

271273
ret

crates/analyzer/src/analyzer_error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3674,6 +3674,8 @@ pub enum InvalidForRangeKind {
36743674
BareExpression,
36753675
/// A range bound elaborates to a negative value.
36763676
NegativeBound,
3677+
/// The loop body can visibly change an input of the continuation bound.
3678+
MutableBound,
36773679
}
36783680

36793681
impl InvalidForRangeKind {
@@ -3683,6 +3685,9 @@ impl InvalidForRangeKind {
36833685
InvalidForRangeKind::NegativeBound => {
36843686
"for-loop range bounds are elaborated as unsigned; rewrite the range to start at 0 and offset inside the body"
36853687
}
3688+
InvalidForRangeKind::MutableBound => {
3689+
"move the assignment outside the loop or iterate over a separate, stable bound"
3690+
}
36863691
}
36873692
}
36883693
}
@@ -3695,6 +3700,9 @@ impl fmt::Display for InvalidForRangeKind {
36953700
.fmt(f)
36963701
}
36973702
InvalidForRangeKind::NegativeBound => "for-loop range bound is negative".fmt(f),
3703+
InvalidForRangeKind::MutableBound => {
3704+
"for-loop continuation bound is modified by the loop body".fmt(f)
3705+
}
36983706
}
36993707
}
37003708
}

0 commit comments

Comments
 (0)