mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 15:48:19 +00:00
parse.y: Make out-of-scope use errors
This was marked to be done in Zeek 5.1, so do it now. The message didn't include a version, unfortunately, but minimally there was a comment when it should happen.
This commit is contained in:
parent
5b2c82c1e9
commit
12d5dca70f
4 changed files with 4 additions and 15 deletions
11
src/parse.y
11
src/parse.y
|
@ -150,7 +150,6 @@ static int expr_list_has_opt_comma = 0;
|
||||||
|
|
||||||
std::vector<std::set<const ID*>> locals_at_this_scope;
|
std::vector<std::set<const ID*>> locals_at_this_scope;
|
||||||
static std::unordered_set<const ID*> out_of_scope_locals;
|
static std::unordered_set<const ID*> out_of_scope_locals;
|
||||||
static std::unordered_set<const ID*> warned_about_locals;
|
|
||||||
|
|
||||||
static Location func_hdr_location;
|
static Location func_hdr_location;
|
||||||
static int func_hdr_cond_epoch = 0;
|
static int func_hdr_cond_epoch = 0;
|
||||||
|
@ -984,13 +983,8 @@ expr:
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( out_of_scope_locals.count(id.get()) > 0 &&
|
if ( out_of_scope_locals.count(id.get()) > 0 )
|
||||||
warned_about_locals.count(id.get()) == 0 )
|
id->Error("use of out-of-scope local; move declaration to outer scope");
|
||||||
{
|
|
||||||
// Remove in v5.1
|
|
||||||
reporter->Warning("use of out-of-scope local %s deprecated; move declaration to outer scope", id->Name());
|
|
||||||
warned_about_locals.insert(id.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
$$ = new NameExpr(std::move(id));
|
$$ = new NameExpr(std::move(id));
|
||||||
}
|
}
|
||||||
|
@ -1532,7 +1526,6 @@ func_body:
|
||||||
|
|
||||||
locals_at_this_scope.clear();
|
locals_at_this_scope.clear();
|
||||||
out_of_scope_locals.clear();
|
out_of_scope_locals.clear();
|
||||||
warned_about_locals.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt_list
|
stmt_list
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
warning in <...>/uninitialized-local2.zeek, line 24: use of out-of-scope local var_b deprecated; move declaration to outer scope
|
error in <...>/uninitialized-local2.zeek, line 16: use of out-of-scope local; move declaration to outer scope (var_b)
|
||||||
expression error in <...>/uninitialized-local2.zeek, line 24: value used but not set (var_b)
|
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
var_a is, baz
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
# For script optimization this test generates hard errors rather than warnings.
|
# For script optimization this test generates hard errors rather than warnings.
|
||||||
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
|
|
||||||
# @TEST-REQUIRES: test "${ZEEK_ZAM}" != "1"
|
|
||||||
#
|
#
|
||||||
# @TEST-EXEC: zeek -b %INPUT >out 2>err
|
# @TEST-EXEC-FAIL: zeek -b %INPUT >out 2>err
|
||||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
|
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
|
||||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff err
|
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff err
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue