Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions runtime/sam/expr/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,7 @@ func (n *numeric) eval(this super.Value) (super.Value, super.Value, *super.Value
if rhs.IsError() {
return super.Null, super.Null, &rhs
}
return enumToIndex(lhs), enumToIndex(rhs), nil
}

// enumToIndex converts an enum to its index value.
func enumToIndex(val super.Value) super.Value {
if _, ok := val.Type().(*super.TypeEnum); ok {
return super.NewValue(super.TypeUint64, val.Bytes())
}
return val
return lhs, rhs, nil
}

type Compare struct {
Expand Down
16 changes: 2 additions & 14 deletions runtime/vam/expr/arith.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (a *Arith) eval(vecs ...vector.Any) (out vector.Any) {
if vec, ok := CheckForNullThenError(vecs); ok {
return vec
}
lhs := enumToIndex(vector.Under(vecs[0]))
rhs := enumToIndex(vector.Under(vecs[1]))
lhs := vector.Under(vecs[0])
rhs := vector.Under(vecs[1])
lhs, rhs, errVal := coerceVals(a.sctx, lhs, rhs)
if errVal != nil {
return errVal
Expand Down Expand Up @@ -71,18 +71,6 @@ func (a *Arith) eval(vecs ...vector.Any) (out vector.Any) {
return f(lhs, rhs)
}

func enumToIndex(vec vector.Any) vector.Any {
switch vec := vec.(type) {
case *vector.View:
if enum, ok := vec.Any.(*vector.Enum); ok {
return vector.Pick(enum.Uint, vec.Index)
}
case *vector.Enum:
return vec.Uint
}
return vec
}

func (a *Arith) evalDivideByZero(kind vector.Kind, lhs, rhs vector.Any) vector.Any {
var errs []uint32
var out vector.Any
Expand Down
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/bool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ input: |
[1,2]
|[1,2]|
|{"x":1}|
"e2"::enum(e1,e2)

output: |
true
Expand All @@ -47,3 +48,4 @@ output: |
error({message:"cannot cast to bool",on:[1,2]})
error({message:"cannot cast to bool",on:|[1,2]|})
error({message:"cannot cast to bool",on:|{"x":1}|})
error({message:"cannot cast to bool",on:"e2"::enum(e1,e2)})
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/bytes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ input: |
null
null::({}|null)
{x:"foo"}
"e2"::enum(e1,e2)
error("bad")

output: |
Expand All @@ -20,4 +21,5 @@ output: |
null::(bytes|null)
null::(bytes|null)
error({message:"cannot cast to bytes",on:{x:"foo"}})
error({message:"cannot cast to bytes",on:"e2"::enum(e1,e2)})
error("bad")
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/duration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ input: |
[1,2]
|[1,2]|
|{"x":1}|
"e2"::enum(e1,e2)

output: |
10d
Expand All @@ -33,3 +34,4 @@ output: |
error({message:"cannot cast to duration",on:[1,2]})
error({message:"cannot cast to duration",on:|[1,2]|})
error({message:"cannot cast to duration",on:|{"x":1}|})
error({message:"cannot cast to duration",on:"e2"::enum(e1,e2)})
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/float.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ input: |
[1,2]
|[1,2]|
|{"x":1}|
"e2"::enum(e1,e2)

output: |
error("bad")
error({message:"cannot cast to float64",on:{x:1}})
error({message:"cannot cast to float64",on:[1,2]})
error({message:"cannot cast to float64",on:|[1,2]|})
error({message:"cannot cast to float64",on:|{"x":1}|})
error({message:"cannot cast to float64",on:"e2"::enum(e1,e2)})
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/int.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ input: |
[1,2]
|[1,2]|
|{"x":1}|
"e2"::enum(e1,e2)

output: |
error("bad")
error({message:"cannot cast to int64",on:{x:1}})
error({message:"cannot cast to int64",on:[1,2]})
error({message:"cannot cast to int64",on:|[1,2]|})
error({message:"cannot cast to int64",on:|{"x":1}|})
error({message:"cannot cast to int64",on:"e2"::enum(e1,e2)})
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/ip.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ input: |
1.1.1.2::=named
34
35
"e2"::enum(e1,e2)
error("bad")

output: |
Expand All @@ -24,4 +25,5 @@ output: |
1.1.1.2
error({message:"cannot cast to ip",on:34})
error({message:"cannot cast to ip",on:35})
error({message:"cannot cast to ip",on:"e2"::enum(e1,e2)})
error("bad")
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ input: |
null
null::({}|null)
1
"e2"::enum(e1,e2)
error("bad")

output: |
Expand All @@ -17,4 +18,5 @@ output: |
null::(null||{int64:|{string:int64}|}|)
null::(null||{int64:|{string:int64}|}|)
error({message:"cannot cast to |{int64:|{string:int64}|}|",on:1})
error({message:"cannot cast to |{int64:|{string:int64}|}|",on:"e2"::enum(e1,e2)})
error("bad")
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/net.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ input: |
10.0.0.0/8::=named
-35
34
"e2"::enum(e1,e2)
error("bad")

output: |
Expand All @@ -22,4 +23,5 @@ output: |
10.0.0.0/8
error({message:"cannot cast to net",on:-35})
error({message:"cannot cast to net",on:34})
error({message:"cannot cast to net",on:"e2"::enum(e1,e2)})
error("bad")
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/record.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ input: |
null
null::({}|null)
1
"e2"::enum(e1,e2)
error("bad")

output: |
Expand All @@ -23,4 +24,5 @@ output: |
null::(null|{a:int64,b:string,c:{},d:[{e:string,f:int64}]})
null::(null|{a:int64,b:string,c:{},d:[{e:string,f:int64}]})
error({message:"cannot cast to {a:int64,b:string,c:{},d:[{e:string,f:int64}]}",on:1})
error({message:"cannot cast to {a:int64,b:string,c:{},d:[{e:string,f:int64}]}",on:"e2"::enum(e1,e2)})
error("bad")
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/time.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ input: |
[1,2]
|[1,2]|
|{"x":1}|
"e2"::enum(e1,e2)

output: |
2023-10-19T23:11:20.999803Z
Expand All @@ -39,3 +40,4 @@ output: |
error({message:"cannot cast to time",on:[1,2]})
error({message:"cannot cast to time",on:|[1,2]|})
error({message:"cannot cast to time",on:|{"x":1}|})
error({message:"cannot cast to time",on:"e2"::enum(e1,e2)})
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/type.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ input: |
"{x:\"foo\"}"
"<int>"
1
"e2"::enum(e1,e2)
null
null::({}|null)
error("bad")
Expand All @@ -20,6 +21,7 @@ output: |
error({message:"cannot cast to type",on:"{x:\"foo\"}"})
error({message:"cannot cast to type",on:"<int>"})
error({message:"cannot cast to type",on:1})
error({message:"cannot cast to type",on:"e2"::enum(e1,e2)})
null::(type|null)
null::(type|null)
error("bad")
2 changes: 2 additions & 0 deletions runtime/ztests/expr/cast/uint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ input: |
[1,2]
|[1,2]|
|{"x":1}|
"e2"::enum(e1,e2)

output: |
error("bad")
error({message:"cannot cast to uint64",on:{x:1}})
error({message:"cannot cast to uint64",on:[1,2]})
error({message:"cannot cast to uint64",on:|[1,2]|})
error({message:"cannot cast to uint64",on:|{"x":1}|})
error({message:"cannot cast to uint64",on:"e2"::enum(e1,e2)})
13 changes: 0 additions & 13 deletions runtime/ztests/expr/enum.yaml

This file was deleted.

Loading