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,9 +219,19 @@ void Attributes::CheckAttr(Attr* a)
|
||||||
Error("&default function type clash");
|
Error("&default function type clash");
|
||||||
}
|
}
|
||||||
else
|
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");
|
Error("&default value has inconsistent type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ATTR_ROTATE_INTERVAL:
|
case ATTR_ROTATE_INTERVAL:
|
||||||
|
|
15
src/Val.cc
15
src/Val.cc
|
@ -2023,7 +2023,22 @@ Val* TableVal::Default(Val* index)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if ( ! def_val )
|
if ( ! def_val )
|
||||||
|
{
|
||||||
|
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);
|
def_val = def_attr->AttrExpr()->Eval(0);
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! def_val )
|
if ( ! def_val )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue