GH-1273: Change SizeExpr to yield "any" type when operating on "any"

This commit is contained in:
Jon Siwek 2020-11-09 19:03:42 -08:00
parent 721b232d94
commit d4528162d1
4 changed files with 31 additions and 1 deletions

View file

@ -1162,7 +1162,9 @@ SizeExpr::SizeExpr(ExprPtr arg_op)
if ( IsError() )
return;
if ( op->GetType()->InternalType() == TYPE_INTERNAL_DOUBLE )
if ( op->GetType()->Tag() == TYPE_ANY )
SetType(base_type(TYPE_ANY));
else if ( op->GetType()->InternalType() == TYPE_INTERNAL_DOUBLE )
SetType(base_type(TYPE_DOUBLE));
else
SetType(base_type(TYPE_COUNT));

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in ./lacks-type-cast.zeek, line 3: requires arithmetic operands (1 + aa)

View file

@ -0,0 +1,6 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
13.0, time
13.0, double
13.0, double
14.0
14.0

View file

@ -0,0 +1,20 @@
# @TEST-EXEC: zeek -b %INPUT >output 2>&1
# @TEST-EXEC: btest-diff output
# @TEST-EXEC-FAIL: zeek -b lacks-type-cast.zeek >error 2>&1
# @TEST-EXEC: btest-diff error
local a: any = double_to_time(13.0);
local aa = |a|;
local aaa = |a as time|;
print a, type_name(a);
print aa, type_name(aa);
print aaa, type_name(aaa);
print 1 + (aa as double);
print 1 + aaa;
@TEST-START-FILE lacks-type-cast.zeek
local a: any = double_to_time(13.0);
local aa = |a|;
print 1 + aa;
@TEST-END-FILE