mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Introduce special treatment for the blank identifier _
Mostly: Do not instantiate variables within for loops and allow reusing differently typed blanks which previously wasn't possible. This may be missing some corner-cases, but the added tests seem to work as expected and nothing else fell apart it seems.
This commit is contained in:
parent
7f7c77ab07
commit
46334f8b59
21 changed files with 318 additions and 20 deletions
54
testing/btest/language/blank-expr-errors.zeek
Normal file
54
testing/btest/language/blank-expr-errors.zeek
Normal file
|
@ -0,0 +1,54 @@
|
|||
# @TEST-DOC: Do not allow to reference the blank identifier.
|
||||
|
||||
# @TEST-EXEC-FAIL: zeek -b %INPUT
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
|
||||
event zeek_init()
|
||||
{
|
||||
local vec = vector( "1", "2", "3" );
|
||||
for ( _, v in vec )
|
||||
print _;
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
event zeek_init()
|
||||
{
|
||||
local _ = vector( "1", "2", "3" );
|
||||
print _;
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
# Ensure it does not work in a module, either.
|
||||
module MyModule;
|
||||
event zeek_init()
|
||||
{
|
||||
local _ = vector( "1", "2", "3" );
|
||||
print _;
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
# Ensure _ can not referenced when it's a const in an export section.
|
||||
# Adding the const _ isn't an error though.
|
||||
module MyModule;
|
||||
|
||||
export {
|
||||
const _: count = 1;
|
||||
}
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
print MyModule::_;
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
# Ensure it does not work in a function.
|
||||
module MyModule;
|
||||
function helper()
|
||||
{
|
||||
local _ = vector( "1", "2", "3" );
|
||||
print _;
|
||||
}
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
helper();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue