mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 04:28:20 +00:00
Avoid assertion/tag error on invalid table constructor index expression
If an index expression in a table constructor isn't a list, don't abort with an assertion failure (on debug builds) or a bad tag check. Instead, mark the constructor expression erroneous and return gracefully. The following... global a_table: table[subnet] of string = { 1.2.3.4/24 = "unspecified", # should have been [1.2.3.4/24] = "unspecified", }; ...now yields: $ zeek ./test.zeek error in ././test.zeek, line 2: table constructor index is not a list (1.2.3.0/24 = unspecified) error in ././test.zeek, line 2: type clash in assignment (a_table = table(1.2.3.0/24 = unspecified))
This commit is contained in:
parent
17347df036
commit
87874a62d1
1 changed files with 7 additions and 1 deletions
|
@ -3605,8 +3605,14 @@ TableConstructorExpr::TableConstructorExpr(ListExprPtr constructor_list,
|
|||
auto val_expr = expr->AsAssignExpr()->GetOp2();
|
||||
auto yield_type = GetType()->AsTableType()->Yield();
|
||||
|
||||
if ( idx_expr->Tag() != EXPR_LIST )
|
||||
{
|
||||
expr->Error("table constructor index is not a list");
|
||||
SetError();
|
||||
return;
|
||||
}
|
||||
|
||||
// Promote LHS
|
||||
assert(idx_expr->Tag() == EXPR_LIST);
|
||||
ExprPList& idx_exprs = idx_expr->AsListExpr()->Exprs();
|
||||
|
||||
if ( idx_exprs.length() != static_cast<int>(indices.size()) )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue