Skip to content

Commit

Permalink
FIX: ensures that REPEAT's counter word is not set on argument error.
Browse files Browse the repository at this point in the history
  • Loading branch information
dockimbel committed Aug 3, 2021
1 parent c30671d commit 2caa527
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
13 changes: 7 additions & 6 deletions compiler.r
Original file line number Diff line number Diff line change
Expand Up @@ -2511,21 +2511,22 @@ red: context [
]
add-symbol name
add-global name
pc: next pc

emit-open-frame 'repeat
comp-expression ;-- fetch the upper limit for the counter
emit 'natives/coerce-counter* ;-- eventually convert float to integer
insert-lf -1
emit-argument-type-check 1 'repeat 'stack/arguments

emit-open-frame 'set
emit-push-word name name ;-- push the word
pc: next pc
emit [
integer/push 0
word/set ;-- initialize the counter word to 0
]
emit-close-frame

emit-open-frame 'repeat
comp-expression ;-- fetch the upper limit for the counter
emit 'natives/coerce-counter* ;-- eventually convert float to integer
insert-lf -1
emit-argument-type-check 1 'repeat 'stack/arguments
emit [loop integer/get stack/arguments]
insert-lf -3
push-call 'repeat
Expand Down
7 changes: 6 additions & 1 deletion tests/source/units/loop-test.red
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Red [

===start-group=== "advanced repeat tests"

--test-- "repeat counter mess"
--test-- "advr1"
rcm-n: 0
repeat rcm-i 10 [
repeat rcm-i 5 [
Expand All @@ -67,6 +67,11 @@ Red [
--assert 50 = rcm-n
unset [rcm-i rcm-n]

--test-- "advr2"
c123: "string"
try [repeat c123 1.2.3.4 [--assert false]] ; don't set counter word on error
--assert c123 == "string"

===end-group===

===start-group=== "basic until tests"
Expand Down

0 comments on commit 2caa527

Please sign in to comment.