Skip to content

Commit 5b090f5

Browse files
committed
Fix position invalidation in unroll_for
1 parent 5e2b2ea commit 5b090f5

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/phl/ecPhlLoopTx.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,11 @@ let process_unroll_for ~cfold side cpos tc =
362362
let tcenv = FApi.t_onalli doi tcenv in
363363

364364
if cfold then begin
365-
let cpos = EcMatching.Position.Notations.(cpos <+| 1) in
365+
(* Use normalized position: pos - 1 is the loop counter initialization
366+
assignment that immediately precedes the while loop at pos.
367+
We cannot reuse the original match-based cpos here because t_doit
368+
has transformed the code, potentially invalidating the match. *)
369+
let cpos = ([], EcMatching.Position.cpos1 (pos - 1)) in
366370
let clen = blen * (List.length zs - 1) in
367371

368372
FApi.t_last (EcPhlCodeTx.t_cfold ~eager:false side cpos (Some clen)) tcenv

0 commit comments

Comments
 (0)