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:
Arne Welzel 2023-03-17 11:59:39 +01:00
parent 5b2c82c1e9
commit 12d5dca70f
4 changed files with 4 additions and 15 deletions

View file

@ -150,7 +150,6 @@ static int expr_list_has_opt_comma = 0;
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*> warned_about_locals;
static Location func_hdr_location;
static int func_hdr_cond_epoch = 0;
@ -984,13 +983,8 @@ expr:
}
else
{
if ( out_of_scope_locals.count(id.get()) > 0 &&
warned_about_locals.count(id.get()) == 0 )
{
// 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());
}
if ( out_of_scope_locals.count(id.get()) > 0 )
id->Error("use of out-of-scope local; move declaration to outer scope");
$$ = new NameExpr(std::move(id));
}
@ -1532,7 +1526,6 @@ func_body:
locals_at_this_scope.clear();
out_of_scope_locals.clear();
warned_about_locals.clear();
}
stmt_list

View file

@ -1,3 +1,2 @@
### 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
expression error in <...>/uninitialized-local2.zeek, line 24: value used but not set (var_b)
error in <...>/uninitialized-local2.zeek, line 16: use of out-of-scope local; move declaration to outer scope (var_b)

View file

@ -1,2 +1 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
var_a is, baz

View file

@ -1,8 +1,6 @@
# 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 err