RecordType: Ensure &default fields are always re-initialized

This started working partly after the deferral logic introduced with
Zeek 6.0 so this finishes it :-)
This commit is contained in:
Arne Welzel 2025-07-27 16:03:40 +02:00
parent 473723cc47
commit 9eb94ee151
4 changed files with 65 additions and 8 deletions

View file

@ -0,0 +1,4 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
default, [v=[1, 2, 3, 100], r=[c=101]]
after changing, [v=[1, 2, 3, 100, 4711], r=[c=42]]
after delete, [v=[1, 2, 3, 102], r=[c=103]]

View file

@ -1,3 +1,5 @@
# @TEST-DOC: Test behavior of &default when deleting a record field and subsequently accessing it again.
#
# @TEST-EXEC: zeek -b %INPUT >output 2>&1
# @TEST-EXEC: btest-diff output
@ -14,3 +16,30 @@ delete test$b;
delete test$c;
print test;
# @TEST-START-NEXT
global c = 99;
# Helper function that's running as part of R's default construction.
function seq(): count {
++c;
return c;
}
type R: record {
c: count &default=seq();
};
type FooBar: record {
v: vector of count &default=vector(1, 2, 3, seq());
r: R &default=R();
};
global test: FooBar;
print "default", test;
test$v += 4711;
test$r$c = 42;
print "after changing", test;
delete test$v;
delete test$r;
print "after delete", test;