mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 16:18:19 +00:00
Fix various bugs with table/set attributes.
- Identifiers that are initialized with set()/table() constructor expressions now inherit attributes from the expression. Before, statements like const i: set[string] = set() &redef; associated the attribute with the set() constructor, but not the "i" identifier, preventing redefinition. Addresses #866. - Allow &default attribute to apply to tables initialized as empty (via either "{ }" or "table()") or if the expression supplied to it can evaluate to a type that's promotable to the same yield type as the table.
This commit is contained in:
parent
00f7bbda96
commit
f7e07f5f09
6 changed files with 249 additions and 1 deletions
28
src/Var.cc
28
src/Var.cc
|
@ -109,6 +109,34 @@ static void make_var(ID* id, BroType* t, init_class c, Expr* init,
|
|||
if ( attr )
|
||||
id->AddAttrs(new Attributes(attr, t, false));
|
||||
|
||||
if ( init )
|
||||
{
|
||||
switch ( init->Tag() ) {
|
||||
case EXPR_TABLE_CONSTRUCTOR:
|
||||
{
|
||||
TableConstructorExpr* ctor = (TableConstructorExpr*) init;
|
||||
if ( ctor->Attrs() )
|
||||
{
|
||||
::Ref(ctor->Attrs());
|
||||
id->AddAttrs(ctor->Attrs());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EXPR_SET_CONSTRUCTOR:
|
||||
{
|
||||
SetConstructorExpr* ctor = (SetConstructorExpr*) init;
|
||||
if ( ctor->Attrs() )
|
||||
{
|
||||
::Ref(ctor->Attrs());
|
||||
id->AddAttrs(ctor->Attrs());
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( id->FindAttr(ATTR_PERSISTENT) || id->FindAttr(ATTR_SYNCHRONIZED) )
|
||||
{
|
||||
if ( dt == VAR_CONST )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue