Fix record coercion with compatible types

Fixes #4722
This commit is contained in:
Evan Typanski 2025-08-04 15:47:09 -04:00
parent 56325d1412
commit 006bef71b5
5 changed files with 70 additions and 0 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.
error in <...>/arithmetic-record-vec-fail.zeek, line 13 and int: type clash for field "a" ((coerce [$a=+1] to WithCount) and int)
error in <...>/arithmetic-record-vec-fail.zeek, line 13 and int: type clash for field "a" ((coerce [$a=-2] to WithCount) and int)
error in <...>/arithmetic-record-vec-fail.zeek, line 13 and double: type clash for field "a" ((coerce [$a=3.0] to WithCount) and double)
error in <...>/arithmetic-record-vec-fail.zeek, line 16 and double: type clash for field "a" ((coerce [$a=1.0] to WithInt) and double)
error in <...>/arithmetic-record-vec-fail.zeek, line 16 and double: type clash for field "a" ((coerce [$a=+2.0] to WithInt) and double)
error in <...>/arithmetic-record-vec-fail.zeek, line 16 and double: type clash for field "a" ((coerce [$a=-3.0] to WithInt) and double)

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.
[[a=1], [a=2], [a=3]]
[[a=1], [a=2], [a=3]]
[[a=1], [a=2], [a=3]]
[[a=1.0], [a=2.0], [a=3.0]]
[[a=1.0], [a=2.0], [a=3.0]]
[[a=1.0], [a=2.0], [a=-3.0]]

View file

@ -0,0 +1,16 @@
# @TEST-EXEC-FAIL: zeek -b %INPUT 2>err
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff err
type WithCount: record {
a: count;
};
type WithInt: record {
a: int;
};
type CountRecVec: vector of WithCount;
global vec_count_fail = CountRecVec([$a=+1], [$a=-2], [$a=3.0]);
type IntRecVec: vector of WithInt;
global vec_int_fail = IntRecVec([$a=1.0], [$a=+2.0], [$a=-3.0]);

View file

@ -0,0 +1,37 @@
# @TEST-DOC: Ensures arithmetic type checking works when adding to vector; regression test for #4722
#
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: btest-diff out
type WithCount: record {
a: count;
};
type WithInt: record {
a: int;
};
type WithDouble: record {
a: double;
};
type CountRecVec: vector of WithCount;
global vec_count = CountRecVec([$a=1], [$a=2], [$a=3]);
type IntRecVec: vector of WithInt;
global vec_int = IntRecVec([$a=+1], [$a=+2], [$a=+3]);
global vec_count_int = IntRecVec([$a=1], [$a=2], [$a=3]);
type DoubleRecVec: vector of WithDouble;
global vec_double = DoubleRecVec([$a=1.0], [$a=2.0], [$a=3.0]);
global vec_count_double = DoubleRecVec([$a=1], [$a=2], [$a=3]);
global vec_int_double = DoubleRecVec([$a=+1], [$a=+2], [$a=-3]);
print vec_count;
print vec_int;
print vec_count_int;
print vec_double;
print vec_count_double;
print vec_int_double;