Merge remote-tracking branch 'origin/topic/robin/gh-2280-modifiable-const-via-loops-merge'

* origin/topic/robin/gh-2280-modifiable-const-via-loops-merge:
  Add help function to check loop variable
  Fix local const variables can be modified via loops
This commit is contained in:
Robin Sommer 2022-07-19 15:20:34 +02:00
commit d5db2623dc
3 changed files with 35 additions and 17 deletions

View file

@ -0,0 +1,5 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/for-var-check.zeek, line 4: global variable used in 'for' loop (x)
error in error and count: type clash in iteration (error and count)
error in <...>/for-var-check.zeek, line 8: constant used in 'for' loop (y)
error in error and count: type clash in iteration (error and count)

View file

@ -0,0 +1,13 @@
# @TEST-EXEC-FAIL: zeek -b %INPUT >out 2>&1
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
global x: count = 0;
event zeek_init()
{
const y: count = 0;
for ( x in set(1, 2, 3) ) {}
for ( y in set(1, 2, 3) ) {}
}