GH-1159: Fix vector-of-interval multiplication/division arithmetic

Those operations done between a vector-of-interval and a
vector-of-arithmetic-type previously threw a runtime expression error
due to an incorrect coercion being used internally.
This commit is contained in:
Jon Siwek 2020-09-14 16:12:20 -07:00
parent 0771dbcec6
commit 3b334bad56
3 changed files with 26 additions and 2 deletions

View file

@ -1414,7 +1414,12 @@ TimesExpr::TimesExpr(ExprPtr arg_op1, ExprPtr arg_op2)
if ( bt1 == TYPE_INTERVAL || bt2 == TYPE_INTERVAL )
{
if ( IsArithmetic(bt1) || IsArithmetic(bt2) )
{
if ( is_vector(op1) && is_vector(op2) )
SetType(make_intrusive<VectorType>(base_type(TYPE_INTERVAL)));
else
PromoteType(TYPE_INTERVAL, is_vector(op1) || is_vector(op2) );
}
else
ExprError("multiplication with interval requires arithmetic operand");
}
@ -1450,7 +1455,12 @@ DivideExpr::DivideExpr(ExprPtr arg_op1, ExprPtr arg_op2)
if ( bt1 == TYPE_INTERVAL || bt2 == TYPE_INTERVAL )
{
if ( IsArithmetic(bt1) || IsArithmetic(bt2) )
{
if ( is_vector(op1) && is_vector(op2) )
SetType(make_intrusive<VectorType>(base_type(TYPE_INTERVAL)));
else
PromoteType(TYPE_INTERVAL, is_vector(op1) || is_vector(op2));
}
else if ( bt1 == TYPE_INTERVAL && bt2 == TYPE_INTERVAL )
{
if ( is_vector(op1) || is_vector(op2) )

View file

@ -0,0 +1,4 @@
[4.0 secs 500.0 msecs, 3.0 mins, 4.0 hrs 30.0 mins]
[4.0 secs 500.0 msecs, 3.0 mins, 4.0 hrs 30.0 mins]
[500.0 msecs, 50.0 msecs, 1.0 msec 250.0 usecs]
[2.0 secs, 20.0 secs, 13.0 mins 20.0 secs]

View file

@ -0,0 +1,10 @@
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: btest-diff out
global v1 = vector(1.5, 3.0, 4.5);
global v2 = vector(3 sec, 1 min, 1 hr);
print v1 * v2;
print v2 * v1;
print v1 / v2;
print v2 / v1;