mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
disambiguate lambdas by adding scoping and consideration of captures
This commit is contained in:
parent
3925ff4592
commit
3e0f814635
2 changed files with 22 additions and 8 deletions
22
src/Expr.cc
22
src/Expr.cc
|
@ -4673,11 +4673,11 @@ LambdaExpr::LambdaExpr(FunctionIngredientsPtr arg_ing, IDPList arg_outer_ids, st
|
|||
else
|
||||
my_name = name;
|
||||
|
||||
// Install that in the global_scope
|
||||
lambda_id = install_ID(my_name.c_str(), "", true, false);
|
||||
// Install that in the current scope.
|
||||
lambda_id = install_ID(my_name.c_str(), current_module.c_str(), true, false);
|
||||
|
||||
// Update lamb's name
|
||||
primary_func->SetName(my_name.c_str());
|
||||
primary_func->SetName(lambda_id->Name());
|
||||
|
||||
auto v = make_intrusive<FuncVal>(primary_func);
|
||||
lambda_id->SetVal(std::move(v));
|
||||
|
@ -4800,6 +4800,17 @@ void LambdaExpr::BuildName()
|
|||
ODesc d;
|
||||
primary_func->Describe(&d);
|
||||
|
||||
if ( captures )
|
||||
for ( auto& c : *captures )
|
||||
{
|
||||
if ( c.IsDeepCopy() )
|
||||
d.AddSP("copy");
|
||||
|
||||
if ( c.Id() )
|
||||
// c.Id() will be nil for some errors
|
||||
c.Id()->Describe(&d);
|
||||
}
|
||||
|
||||
for ( ;; )
|
||||
{
|
||||
hash128_t h;
|
||||
|
@ -4807,7 +4818,7 @@ void LambdaExpr::BuildName()
|
|||
|
||||
my_name = "lambda_<" + std::to_string(h[0]) + ">";
|
||||
auto fullname = make_full_var_name(current_module.data(), my_name.data());
|
||||
const auto& id = global_scope()->Find(fullname);
|
||||
const auto& id = current_scope()->Find(fullname);
|
||||
|
||||
if ( id )
|
||||
// Just try again to make a unique lambda name.
|
||||
|
@ -4873,6 +4884,9 @@ void LambdaExpr::ExprDescribe(ODesc* d) const
|
|||
if ( &c != &(*captures)[0] )
|
||||
d->AddSP(", ");
|
||||
|
||||
if ( c.IsDeepCopy() )
|
||||
d->AddSP("copy");
|
||||
|
||||
d->Add(c.Id()->Name());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/closure-binding-errors.zeek, line 12: a is captured but not used inside lambda (function(){ print no a!})
|
||||
error in <...>/closure-binding-errors.zeek, line 12: a is captured but not used inside lambda (function()[a]{ print no a!})
|
||||
error in <...>/closure-binding-errors.zeek, line 13: no such local identifier: a2
|
||||
error in <...>/closure-binding-errors.zeek, line 14: b is used inside lambda but not captured (function(){ print b})
|
||||
error in <...>/closure-binding-errors.zeek, line 15: a is captured but not used inside lambda (function(){ print b})
|
||||
error in <...>/closure-binding-errors.zeek, line 16: b listed multiple times in capture (function(){ print b})
|
||||
error in <...>/closure-binding-errors.zeek, line 14: b is used inside lambda but not captured (function()[a]{ print b})
|
||||
error in <...>/closure-binding-errors.zeek, line 15: a is captured but not used inside lambda (function()[a, b]{ print b})
|
||||
error in <...>/closure-binding-errors.zeek, line 16: b listed multiple times in capture (function()[b, b]{ print b})
|
||||
error in <...>/closure-binding-errors.zeek, line 18: cannot specify global in capture: c
|
||||
error in <...>/closure-binding-errors.zeek, line 19: cannot specify type in capture: t
|
||||
error in <...>/closure-binding-errors.zeek, line 9 and <...>/closure-binding-errors.zeek, line 20: already defined (a)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue