mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
GH-654: allow table() in record &default expressions
Table fields of records previously did not coerce unspecified tables used in their &default attribute to the correct type.
This commit is contained in:
parent
691fd5c9a4
commit
34bf78984b
3 changed files with 23 additions and 2 deletions
14
src/Attr.cc
14
src/Attr.cc
|
@ -372,11 +372,21 @@ void Attributes::CheckAttr(Attr* a)
|
|||
{
|
||||
// &default applies to record field.
|
||||
|
||||
if ( same_type(atype, type) ||
|
||||
(atype->Tag() == TYPE_TABLE && atype->AsTableType()->IsUnspecifiedTable()) )
|
||||
if ( same_type(atype, type) )
|
||||
// Ok.
|
||||
break;
|
||||
|
||||
if ( (atype->Tag() == TYPE_TABLE && atype->AsTableType()->IsUnspecifiedTable()) )
|
||||
{
|
||||
Expr* e = a->AttrExpr();
|
||||
|
||||
if ( check_and_promote_expr(e, type) )
|
||||
{
|
||||
a->SetAttrExpr(e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Table defaults may be promotable.
|
||||
if ( ytype && ytype->Tag() == TYPE_RECORD &&
|
||||
atype->Tag() == TYPE_RECORD &&
|
||||
|
|
|
@ -20,3 +20,6 @@
|
|||
0
|
||||
[a=13, c=13, v=[test]]
|
||||
1
|
||||
[a={
|
||||
[one] = 1
|
||||
}]
|
||||
|
|
|
@ -17,6 +17,10 @@ type Bar: record {
|
|||
foo: Foo &default=[$foo=1234];
|
||||
};
|
||||
|
||||
type Qux: record {
|
||||
a: table[string] of string &default=table();
|
||||
};
|
||||
|
||||
function print_bar(b: Bar)
|
||||
{
|
||||
print b;
|
||||
|
@ -46,3 +50,7 @@ print |r$v|;
|
|||
r$v += "test";
|
||||
print r;
|
||||
print |r$v|;
|
||||
|
||||
local q = Qux();
|
||||
q$a["one"] = "1";
|
||||
print q;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue