mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Fix for nested "when" statements leading to confusion over scoping
This commit is contained in:
parent
0b217e0e76
commit
a1d25670fc
3 changed files with 25 additions and 14 deletions
14
src/Var.cc
14
src/Var.cc
|
@ -767,7 +767,6 @@ class OuterIDBindingFinder : public TraversalCallback
|
||||||
public:
|
public:
|
||||||
OuterIDBindingFinder(ScopePtr s) { scopes.emplace_back(s); }
|
OuterIDBindingFinder(ScopePtr s) { scopes.emplace_back(s); }
|
||||||
|
|
||||||
TraversalCode PreStmt(const Stmt*) override;
|
|
||||||
TraversalCode PreExpr(const Expr*) override;
|
TraversalCode PreExpr(const Expr*) override;
|
||||||
TraversalCode PostExpr(const Expr*) override;
|
TraversalCode PostExpr(const Expr*) override;
|
||||||
|
|
||||||
|
@ -775,19 +774,6 @@ public:
|
||||||
std::unordered_set<ID*> outer_id_references;
|
std::unordered_set<ID*> outer_id_references;
|
||||||
};
|
};
|
||||||
|
|
||||||
TraversalCode OuterIDBindingFinder::PreStmt(const Stmt* stmt)
|
|
||||||
{
|
|
||||||
if ( stmt->Tag() != STMT_WHEN )
|
|
||||||
return TC_CONTINUE;
|
|
||||||
|
|
||||||
auto ws = static_cast<const WhenStmt*>(stmt);
|
|
||||||
|
|
||||||
for ( auto& cl : ws->Info()->WhenExprLocals() )
|
|
||||||
outer_id_references.insert(const_cast<ID*>(cl.get()));
|
|
||||||
|
|
||||||
return TC_ABORTSTMT;
|
|
||||||
}
|
|
||||||
|
|
||||||
TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr)
|
TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr)
|
||||||
{
|
{
|
||||||
if ( expr->Tag() == EXPR_LAMBDA )
|
if ( expr->Tag() == EXPR_LAMBDA )
|
||||||
|
|
3
testing/btest/Baseline/language.when-scope/out
Normal file
3
testing/btest/Baseline/language.when-scope/out
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
10.0.0.1
|
||||||
|
10.0.0.2
|
22
testing/btest/language/when-scope.zeek
Normal file
22
testing/btest/language/when-scope.zeek
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# @TEST-DOC: Check for regression of "when" capture confusion over outer scope
|
||||||
|
#
|
||||||
|
# @TEST-EXEC: zeek -b %INPUT | sort >out
|
||||||
|
# @TEST-EXEC: btest-diff out
|
||||||
|
|
||||||
|
module Test;
|
||||||
|
|
||||||
|
event zeek_init()
|
||||||
|
{
|
||||||
|
local myset = set(10.0.0.1, 10.0.0.2);
|
||||||
|
|
||||||
|
when [myset] (T)
|
||||||
|
{
|
||||||
|
for ( ip in myset )
|
||||||
|
{
|
||||||
|
when [ip] ( ip == ip )
|
||||||
|
{
|
||||||
|
print fmt("%s", ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue