From 12d5dca70f2bde473c100215be11be365c1c569a Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Fri, 17 Mar 2023 11:59:39 +0100 Subject: [PATCH] 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. --- src/parse.y | 11 ++--------- .../btest/Baseline/language.uninitialized-local2/err | 3 +-- .../btest/Baseline/language.uninitialized-local2/out | 1 - testing/btest/language/uninitialized-local2.zeek | 4 +--- 4 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/parse.y b/src/parse.y index 1cc52b0a2a..92a22c81d7 100644 --- a/src/parse.y +++ b/src/parse.y @@ -150,7 +150,6 @@ static int expr_list_has_opt_comma = 0; std::vector> locals_at_this_scope; static std::unordered_set out_of_scope_locals; -static std::unordered_set 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 diff --git a/testing/btest/Baseline/language.uninitialized-local2/err b/testing/btest/Baseline/language.uninitialized-local2/err index 3dbb74b315..d80da35529 100644 --- a/testing/btest/Baseline/language.uninitialized-local2/err +++ b/testing/btest/Baseline/language.uninitialized-local2/err @@ -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) diff --git a/testing/btest/Baseline/language.uninitialized-local2/out b/testing/btest/Baseline/language.uninitialized-local2/out index ba5c5cef5e..49d861c74c 100644 --- a/testing/btest/Baseline/language.uninitialized-local2/out +++ b/testing/btest/Baseline/language.uninitialized-local2/out @@ -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 diff --git a/testing/btest/language/uninitialized-local2.zeek b/testing/btest/language/uninitialized-local2.zeek index be1dcf6e82..411ac0f5f7 100644 --- a/testing/btest/language/uninitialized-local2.zeek +++ b/testing/btest/language/uninitialized-local2.zeek @@ -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