mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 00:28:21 +00:00
GH-955: Prohibit fallthrough
in typecasting switch
cases
This commit is contained in:
parent
ff0aa6b050
commit
3368958ac1
4 changed files with 101 additions and 5 deletions
|
@ -0,0 +1,3 @@
|
|||
error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.switch-type-cast-fallthrough-error/switch-type-cast-fallthrough-error.zeek, line 9: invalid 'fallthrough' in type-casting 'case' block
|
||||
error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.switch-type-cast-fallthrough-error/switch-type-cast-fallthrough-error.zeek, line 20: invalid 'fallthrough' in type-casting 'case' block
|
||||
error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.switch-type-cast-fallthrough-error/switch-type-cast-fallthrough-error.zeek, line 22: invalid 'fallthrough' in type-casting 'case' block
|
|
@ -0,0 +1,64 @@
|
|||
# @TEST-EXEC-FAIL: zeek -b %INPUT >out 2>&1
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
|
||||
|
||||
local x: any = 0;
|
||||
|
||||
switch ( x ) {
|
||||
case type count as i:
|
||||
print "count", i;
|
||||
fallthrough; # This is invalid
|
||||
case type double as d:
|
||||
print "double", d;
|
||||
break;
|
||||
}
|
||||
|
||||
switch ( x ) {
|
||||
case type count as i:
|
||||
print "count", i;
|
||||
|
||||
if ( i == 0 )
|
||||
fallthrough; # This is invalid
|
||||
else
|
||||
fallthrough; # This is invalid
|
||||
|
||||
break;
|
||||
case type double as d:
|
||||
print "double", d;
|
||||
break;
|
||||
}
|
||||
|
||||
switch ( x ) {
|
||||
case type count as i:
|
||||
print "count", i;
|
||||
|
||||
switch ( x as count ) {
|
||||
case 0:
|
||||
fallthrough; # This is valid (inside nested switch statement)
|
||||
case 1:
|
||||
print "1";
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case type double as d:
|
||||
print "double", d;
|
||||
break;
|
||||
}
|
||||
|
||||
switch ( x as count ) {
|
||||
case 0:
|
||||
print "0";
|
||||
fallthrough;
|
||||
case 1:
|
||||
print "1";
|
||||
break;
|
||||
}
|
||||
|
||||
switch ( x ) {
|
||||
case type count:
|
||||
print "count";
|
||||
fallthrough;
|
||||
case type double:
|
||||
print "double";
|
||||
break;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue