Skip to content

Commit 722317d

Browse files
authored
vam cast: Fix panic when cast from complex to number (#6665)
1 parent 7a4cb7d commit 722317d

File tree

7 files changed

+90
-10
lines changed

7 files changed

+90
-10
lines changed

runtime/vam/expr/cast/number.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ type numeric interface {
1717
}
1818

1919
func castToNumber(vec vector.Any, typ super.Type, index []uint32) (vector.Any, []uint32, string, bool) {
20-
if vec.Type().ID() == super.IDString {
20+
switch id := vec.Type().ID(); {
21+
case id == super.IDString:
2122
out, errs := castStringToNumber(vec, typ, index)
2223
return out, errs, "", true
24+
case !super.IsNumber(id) && id != super.IDBool:
25+
return nil, nil, "", false
2326
}
2427
switch id := typ.ID(); {
2528
case super.IsSigned(id):

runtime/ztests/expr/cast/bool.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ input: |
1919
null
2020
"1"
2121
error("bad")
22+
{x:1}
23+
[1,2]
24+
|[1,2]|
25+
|{"x":1}|
2226
2327
output: |
2428
true
@@ -37,3 +41,7 @@ output: |
3741
error({message:"cannot cast to bool",on:null})
3842
true
3943
error("bad")
44+
error({message:"cannot cast to bool",on:{x:1}})
45+
error({message:"cannot cast to bool",on:[1,2]})
46+
error({message:"cannot cast to bool",on:|[1,2]|})
47+
error({message:"cannot cast to bool",on:|{"x":1}|})

runtime/ztests/expr/cast/duration.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ input: |
1212
1e+19
1313
null
1414
error("bad")
15+
{x:1}
16+
[1,2]
17+
|[1,2]|
18+
|{"x":1}|
1519
1620
output: |
1721
10d
@@ -23,3 +27,7 @@ output: |
2327
error({message:"cannot cast to duration",on:1e+19})
2428
error({message:"cannot cast to duration",on:null})
2529
error("bad")
30+
error({message:"cannot cast to duration",on:{x:1}})
31+
error({message:"cannot cast to duration",on:[1,2]})
32+
error({message:"cannot cast to duration",on:|[1,2]|})
33+
error({message:"cannot cast to duration",on:|{"x":1}|})

runtime/ztests/expr/cast/float.yaml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ input: |
1111
2::=named
1212
false
1313
true
14-
null
15-
error("bad")
1614
1715
output: |
1816
1.5::float16
@@ -39,9 +37,25 @@ output: |
3937
1.::float16
4038
1.::float32
4139
1.
42-
error({message:"cannot cast to float16",on:null})
43-
error({message:"cannot cast to float32",on:null})
44-
error({message:"cannot cast to float64",on:null})
45-
error("bad")
40+
41+
---
42+
43+
spq: cast(this, <float64>)
44+
45+
vector: true
46+
47+
input: |
48+
null
4649
error("bad")
50+
{x:1}
51+
[1,2]
52+
|[1,2]|
53+
|{"x":1}|
54+
55+
output: |
56+
error({message:"cannot cast to float64",on:null})
4757
error("bad")
58+
error({message:"cannot cast to float64",on:{x:1}})
59+
error({message:"cannot cast to float64",on:[1,2]})
60+
error({message:"cannot cast to float64",on:|[1,2]|})
61+
error({message:"cannot cast to float64",on:|{"x":1}|})

runtime/ztests/expr/cast/int.yaml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ input: |
1414
1e8
1515
false
1616
true
17-
error("bad")
1817
1918
output: |
2019
-1::int8
@@ -57,7 +56,25 @@ output: |
5756
1::int16
5857
1::int32
5958
1
59+
60+
---
61+
62+
spq: cast(this, <int64>)
63+
64+
vector: true
65+
66+
input: |
67+
null
6068
error("bad")
69+
{x:1}
70+
[1,2]
71+
|[1,2]|
72+
|{"x":1}|
73+
74+
output: |
75+
error({message:"cannot cast to int64",on:null})
6176
error("bad")
62-
error("bad")
63-
error("bad")
77+
error({message:"cannot cast to int64",on:{x:1}})
78+
error({message:"cannot cast to int64",on:[1,2]})
79+
error({message:"cannot cast to int64",on:|[1,2]|})
80+
error({message:"cannot cast to int64",on:|{"x":1}|})

runtime/ztests/expr/cast/time.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ input: |
1515
null
1616
1e200
1717
error("bad")
18+
{x:1}
19+
[1,2]
20+
|[1,2]|
21+
|{"x":1}|
1822
1923
output: |
2024
2023-10-19T23:11:20.999803Z
@@ -29,3 +33,7 @@ output: |
2933
error({message:"cannot cast to time",on:null})
3034
error({message:"cannot cast to time",on:1e+200})
3135
error("bad")
36+
error({message:"cannot cast to time",on:{x:1}})
37+
error({message:"cannot cast to time",on:[1,2]})
38+
error({message:"cannot cast to time",on:|[1,2]|})
39+
error({message:"cannot cast to time",on:|{"x":1}|})

runtime/ztests/expr/cast/uint.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,25 @@ output: |
3131
error("bad")
3232
error("bad")
3333
error("bad")
34+
35+
---
36+
37+
spq: cast(this, <uint64>)
38+
39+
vector: true
40+
41+
input: |
42+
null
43+
error("bad")
44+
{x:1}
45+
[1,2]
46+
|[1,2]|
47+
|{"x":1}|
48+
49+
output: |
50+
error({message:"cannot cast to uint64",on:null})
51+
error("bad")
52+
error({message:"cannot cast to uint64",on:{x:1}})
53+
error({message:"cannot cast to uint64",on:[1,2]})
54+
error({message:"cannot cast to uint64",on:|[1,2]|})
55+
error({message:"cannot cast to uint64",on:|{"x":1}|})

0 commit comments

Comments
 (0)