commit 89b74f28f03a195eac50eb8b6f0ed6a844f1f007
parent 8d2d67b2cbcd5c6322e9fb12c63ee107ed841da6
Author: Vlad-Stefan Harbuz <vlad@vlad.website>
Date: Sat, 28 Dec 2024 18:32:01 +0000
regex: change extraneous increment to assertion
See https://lists.sr.ht/~sircmpwn/hare-dev/%3C0d1adb8a-1842-4364-881e-d7163d919d0b@app.fastmail.com%3E
Signed-off-by: Vlad-Stefan Harbuz <vlad@vlad.website>
Diffstat:
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/regex/regex.ha b/regex/regex.ha
@@ -341,12 +341,13 @@ export fn compile(expr: str) (regex | error) = {
jump_idxs[group_level][len(jump_idxs[group_level]) - 1] + 1 else origin;
insert(insts[split_idx], newinst);
shift(insts[split_idx + 1..]);
- // we have to now fix up all affected jump_idxs, since
- // we've shifted them over using the insert
- for (let jump_idx &.. jump_idxs[group_level]) {
- if (*jump_idx >= split_idx) {
- *jump_idx += 1;
- };
+ // our insertion of our split_idx should never interfere
+ // with an existing jump_idx
+ for (let jump_idx .. jump_idxs[group_level]) {
+ // if this assertion ends up being hit in the
+ // future, it is a sign that jump_idx should be
+ // incremented
+ assert(jump_idx < split_idx, `Found jump_idx interference. Please report this as a bug`);
};
append(jump_idxs[group_level], len(insts) - 1);
// add skip if it's a whole-expression alternation