mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00
Fix ambiguity between composite table index and record ctor expressions.
For tables of a composite index type with the first type being a record, membership checks with an inline index key could be misinterpreted as a record constructor instead of an expression list. E.g, if the table type is "global t = table[conn_id, bool] of count", then checking membership like "[c$id, is_orig] in t" now works. Addresses #80.
This commit is contained in:
parent
5508a5bb80
commit
56e359ca9d
3 changed files with 37 additions and 10 deletions
25
src/parse.y
25
src/parse.y
|
@ -456,17 +456,24 @@ expr:
|
|||
|
||||
| '[' expr_list ']'
|
||||
{
|
||||
// A little crufty: we peek at the type of
|
||||
// the first expression in the list. If it's
|
||||
// a record or a field assignment, then this
|
||||
// is a record constructor. If not, then this
|
||||
// is a list used for an initializer.
|
||||
|
||||
set_location(@1, @3);
|
||||
|
||||
Expr* e0 = $2->Exprs()[0];
|
||||
if ( e0->Tag() == EXPR_FIELD_ASSIGN ||
|
||||
e0->Type()->Tag() == TYPE_RECORD )
|
||||
bool is_record_ctor = true;
|
||||
|
||||
// If every expression in the list is a field assignment,
|
||||
// then treat it as a record constructor, else as a list
|
||||
// used for an initializer.
|
||||
|
||||
for ( int i = 0; i < $2->Exprs().length(); ++i )
|
||||
{
|
||||
if ( $2->Exprs()[i]->Tag() != EXPR_FIELD_ASSIGN )
|
||||
{
|
||||
is_record_ctor = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_record_ctor )
|
||||
$$ = new RecordConstructorExpr($2);
|
||||
else
|
||||
$$ = $2;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue