Type/is_supported_index_type: Deal with recursive record types

This plugs the issue reported in #2690, there might be more though.

Closes #2690
This commit is contained in:
Arne Welzel 2023-02-15 16:43:26 +01:00
parent 8e2d68ffec
commit ec998dbfb6
4 changed files with 118 additions and 7 deletions

View file

@ -0,0 +1,7 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
===, 0, {
}
===, 1, {
[[id=1, foo=<uninitialized>]] = [id=2, foo=[id=1, foo=<uninitialized>]]
}

View file

@ -0,0 +1,38 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
===, 1, {
[[bar=1, parent={
}]] = {
1
}
}
{
[[bar=1, parent={
}]] = {
1
}
}
===, 2, {
[[bar=1, parent={
}]] = {
1
},
[[bar=1, parent={
[T] = [bar=2, parent={
}]
}]] = {
2
}
}
===, 1, {
[[bar=1, parent={
[T] = [bar=2, parent={
}]
}]] = {
2
}
}

View file

@ -0,0 +1,56 @@
# @TEST-EXEC: zeek -b %INPUT >output
# @TEST-EXEC: btest-diff output
type Foo: record {
bar: count;
};
redef record Foo += {
parent: table[bool] of Foo &default=table();
};
event zeek_init()
{
local tbl: table[Foo] of set[count];
local f = Foo($bar=1);
tbl[f] = set(1);
print "===", |tbl|, tbl;
print tbl;
local parent_tbl: table[bool] of Foo = [
[T] = Foo($bar=2),
];
f$parent = parent_tbl;
tbl[f] = set(2);
# This now has two entries in the table, because
# after setting f$parent, that's a different key.
print "===", |tbl|, tbl;
# Mutate f and use it to delete the first entry again.
f$parent = table();
delete tbl[f];
# This will be size 1
print "===", |tbl|, tbl;
}
#@TEST-START-NEXT
type Foo: record {
id: string;
};
redef record Foo += {
foo: Foo &optional;
};
event zeek_init()
{
local tbl: table[Foo] of Foo;
local f1 = Foo($id="1");
local f2 = Foo($id="2", $foo=f1);
print "===", |tbl|, tbl;
tbl[f1] = f2;
print "===", |tbl|, tbl;
}