mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Enabling record coercion for a table's &default attribute.
This commit is contained in:
parent
51f9cb2ac5
commit
83bd6584ee
2 changed files with 26 additions and 1 deletions
10
src/Attr.cc
10
src/Attr.cc
|
@ -219,7 +219,17 @@ void Attributes::CheckAttr(Attr* a)
|
|||
Error("&default function type clash");
|
||||
}
|
||||
else
|
||||
{
|
||||
BroType* ytype = tt->YieldType();
|
||||
|
||||
// Table defaults may be promotable.
|
||||
if ( atype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD &&
|
||||
record_promotion_compatible(atype->AsRecordType(), ytype->AsRecordType()) )
|
||||
// Ok.
|
||||
break;
|
||||
|
||||
Error("&default value has inconsistent type");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
17
src/Val.cc
17
src/Val.cc
|
@ -2023,7 +2023,22 @@ Val* TableVal::Default(Val* index)
|
|||
return 0;
|
||||
|
||||
if ( ! def_val )
|
||||
def_val = def_attr->AttrExpr()->Eval(0);
|
||||
{
|
||||
BroType* ytype = Type()->YieldType();
|
||||
BroType* dtype = def_attr->AttrExpr()->Type();
|
||||
|
||||
if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD &&
|
||||
! same_type(dtype, ytype) &&
|
||||
record_promotion_compatible(dtype->AsRecordType(), ytype->AsRecordType()) )
|
||||
{
|
||||
Expr* coerce = new RecordCoerceExpr(def_attr->AttrExpr(), ytype->AsRecordType());
|
||||
def_val = coerce->Eval(0);
|
||||
Unref(coerce);
|
||||
}
|
||||
|
||||
else
|
||||
def_val = def_attr->AttrExpr()->Eval(0);
|
||||
}
|
||||
|
||||
if ( ! def_val )
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue