mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Check table yield type on assignment.
This commit is contained in:
parent
d886f40728
commit
4ae764f74b
1 changed files with 17 additions and 2 deletions
19
src/Expr.cc
19
src/Expr.cc
|
@ -2553,8 +2553,8 @@ bool AssignExpr::TypeCheck(attr_list* attrs)
|
|||
|
||||
if ( bt1 == TYPE_TABLE && op2->Tag() == EXPR_LIST )
|
||||
{
|
||||
bool empty_list_assignment = (op2->AsListExpr()->Exprs().length() == 0);
|
||||
attr_list* attr_copy = 0;
|
||||
|
||||
if ( attrs )
|
||||
{
|
||||
attr_copy = new attr_list(attrs->length());
|
||||
|
@ -2565,7 +2565,22 @@ bool AssignExpr::TypeCheck(attr_list* attrs)
|
|||
if ( op1->Type()->IsSet() )
|
||||
op2 = new SetConstructorExpr(op2->AsListExpr(), attr_copy);
|
||||
else
|
||||
op2 = new TableConstructorExpr(op2->AsListExpr(), attr_copy);
|
||||
{
|
||||
op2 = new TableConstructorExpr(op2->AsListExpr(), attr_copy);
|
||||
|
||||
// Verify that both tables yield the same type.
|
||||
// Skip when assigning to empty lists.
|
||||
if (!empty_list_assignment)
|
||||
{
|
||||
const BroType* yield1 = op1->Type()->AsTableType()->YieldType();
|
||||
const BroType* yield2 = op2->Type()->AsTableType()->YieldType();
|
||||
if (yield1->Tag() != TYPE_ANY && !same_type(yield1, yield2))
|
||||
{
|
||||
ExprError("table yield type mismatch");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue