diff --git a/src/Attr.cc b/src/Attr.cc index c6cf036642..d63f72a3fd 100644 --- a/src/Attr.cc +++ b/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 && diff --git a/testing/btest/Baseline/language.record-default-coercion/out b/testing/btest/Baseline/language.record-default-coercion/out index bf76ba5033..0e9619bbd4 100644 --- a/testing/btest/Baseline/language.record-default-coercion/out +++ b/testing/btest/Baseline/language.record-default-coercion/out @@ -20,3 +20,6 @@ 0 [a=13, c=13, v=[test]] 1 +[a={ +[one] = 1 +}] diff --git a/testing/btest/language/record-default-coercion.zeek b/testing/btest/language/record-default-coercion.zeek index 83e48044a3..231edc7b60 100644 --- a/testing/btest/language/record-default-coercion.zeek +++ b/testing/btest/language/record-default-coercion.zeek @@ -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;