mirror of
https://github.com/zeek/zeek.git
synced 2025-10-13 03:58:20 +00:00
restored record constructor checking for missing-but-mandatory fields
This commit is contained in:
parent
9b184c3d4a
commit
3e0b46b963
1 changed files with 23 additions and 0 deletions
23
src/Expr.cc
23
src/Expr.cc
|
@ -3375,6 +3375,8 @@ RecordConstructorExpr::RecordConstructorExpr(RecordTypePtr known_rt, ListExprPtr
|
|||
const auto& exprs = op->AsListExpr()->Exprs();
|
||||
map = std::vector<int>(exprs.length());
|
||||
|
||||
std::set<int> fields_seen; // used to check for missing fields
|
||||
|
||||
int i = 0;
|
||||
for ( const auto& e : exprs )
|
||||
{
|
||||
|
@ -3401,6 +3403,27 @@ RecordConstructorExpr::RecordConstructorExpr(RecordTypePtr known_rt, ListExprPtr
|
|||
SetError();
|
||||
|
||||
(*map)[i++] = index;
|
||||
fields_seen.insert(index);
|
||||
}
|
||||
|
||||
if ( IsError() )
|
||||
return;
|
||||
|
||||
auto n = known_rt->NumFields();
|
||||
for ( i = 0; i < n; ++i )
|
||||
if ( fields_seen.count(i) == 0 )
|
||||
{
|
||||
const auto td_i = known_rt->FieldDecl(i);
|
||||
if ( IsAggr(td_i->type) )
|
||||
// These are always initialized.
|
||||
continue;
|
||||
|
||||
if ( ! td_i->GetAttr(ATTR_OPTIONAL) )
|
||||
{
|
||||
auto err = std::string("mandatory field \"") + known_rt->FieldName(i) +
|
||||
"\" missing";
|
||||
ExprError(err.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue