mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
bug fix for reporting poorly formed record constructors
This commit is contained in:
parent
1e60264548
commit
4f566f35ee
3 changed files with 25 additions and 1 deletions
|
@ -3307,11 +3307,15 @@ RecordConstructorExpr::RecordConstructorExpr(ListExprPtr constructor_list)
|
|||
const ExprPList& exprs = op->AsListExpr()->Exprs();
|
||||
type_decl_list* record_types = new type_decl_list(exprs.length());
|
||||
|
||||
const Expr* constructor_error_expr = nullptr;
|
||||
|
||||
for ( const auto& e : exprs )
|
||||
{
|
||||
if ( e->Tag() != EXPR_FIELD_ASSIGN )
|
||||
{
|
||||
Error("bad type in record constructor", e);
|
||||
// Don't generate the error yet, as reporting it
|
||||
// requires that we have a well-formed type.
|
||||
constructor_error_expr = e;
|
||||
SetError();
|
||||
continue;
|
||||
}
|
||||
|
@ -3323,6 +3327,9 @@ RecordConstructorExpr::RecordConstructorExpr(ListExprPtr constructor_list)
|
|||
}
|
||||
|
||||
SetType(make_intrusive<RecordType>(record_types));
|
||||
|
||||
if ( constructor_error_expr )
|
||||
Error("bad type in record constructor", constructor_error_expr);
|
||||
}
|
||||
|
||||
RecordConstructorExpr::RecordConstructorExpr(RecordTypePtr known_rt, ListExprPtr constructor_list)
|
||||
|
|
2
testing/btest/Baseline/language.record-bad-ctor3/out
Normal file
2
testing/btest/Baseline/language.record-bad-ctor3/out
Normal file
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/record-bad-ctor3.zeek, line 13: bad type in record constructor ([$x=a + 5, a + 9] and a + 9)
|
15
testing/btest/language/record-bad-ctor3.zeek
Normal file
15
testing/btest/language/record-bad-ctor3.zeek
Normal file
|
@ -0,0 +1,15 @@
|
|||
# @TEST-EXEC-FAIL: zeek -b %INPUT >out 2>&1
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
|
||||
|
||||
# Every element in a record ctor's expression list should have an assignment
|
||||
# form. Make sure we correctly report errors when that's not the case.
|
||||
|
||||
global a = 3;
|
||||
|
||||
type r: record { x: count; y: count; };
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
local b: r = record($x = a + 5, a + 9);
|
||||
print b;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue