mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 17:48:21 +00:00
Change record ctors to only allow record-field-assignment expressions.
Previously, any expression that evaluates to a record may have been used in a record ctor's expression list. This didn't work in all cases, doesn't provide any unique functionality that can't be done otherwise, and is possibly a path to introducing subtle scripting errors. BIT-1192 #closed
This commit is contained in:
parent
aa81825104
commit
aee708c703
5 changed files with 30 additions and 23 deletions
29
src/Expr.cc
29
src/Expr.cc
|
@ -3398,8 +3398,8 @@ RecordConstructorExpr::RecordConstructorExpr(ListExpr* constructor_list)
|
|||
if ( IsError() )
|
||||
return;
|
||||
|
||||
// Spin through the list, which should be comprised of
|
||||
// either record's or record-field-assign, and build up a
|
||||
// Spin through the list, which should be comprised only of
|
||||
// record-field-assign expressions, and build up a
|
||||
// record type to associate with this constructor.
|
||||
type_decl_list* record_types = new type_decl_list;
|
||||
|
||||
|
@ -3409,32 +3409,17 @@ RecordConstructorExpr::RecordConstructorExpr(ListExpr* constructor_list)
|
|||
Expr* e = exprs[i];
|
||||
BroType* t = e->Type();
|
||||
|
||||
if ( e->Tag() == EXPR_FIELD_ASSIGN )
|
||||
{
|
||||
FieldAssignExpr* field = (FieldAssignExpr*) e;
|
||||
|
||||
BroType* field_type = field->Type()->Ref();
|
||||
char* field_name = copy_string(field->FieldName());
|
||||
|
||||
record_types->append(new TypeDecl(field_type, field_name));
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( t->Tag() != TYPE_RECORD )
|
||||
if ( e->Tag() != EXPR_FIELD_ASSIGN )
|
||||
{
|
||||
Error("bad type in record constructor", e);
|
||||
SetError();
|
||||
continue;
|
||||
}
|
||||
|
||||
// It's a record - add in its fields.
|
||||
const RecordType* rt = t->AsRecordType();
|
||||
int n = rt->NumFields();
|
||||
for ( int j = 0; j < n; ++j )
|
||||
{
|
||||
const TypeDecl* td = rt->FieldDecl(j);
|
||||
record_types->append(new TypeDecl(td->type->Ref(), td->id));
|
||||
}
|
||||
FieldAssignExpr* field = (FieldAssignExpr*) e;
|
||||
BroType* field_type = field->Type()->Ref();
|
||||
char* field_name = copy_string(field->FieldName());
|
||||
record_types->append(new TypeDecl(field_type, field_name));
|
||||
}
|
||||
|
||||
SetType(new RecordType(record_types));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue