Skip to content

Commit

Permalink
lang: core, funcs: Use the correct zero type
Browse files Browse the repository at this point in the history
I wasn't using the correct contained type here.
  • Loading branch information
purpleidea committed Sep 11, 2024
1 parent 2e77421 commit 9a5f6a5
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lang/core/list/list_lookup_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (obj *ListLookupFunc) Copy() interfaces.Func {
func (obj *ListLookupFunc) Function(ctx context.Context, input []types.Value) (types.Value, error) {
l := (input[0]).(*types.ListValue)
index := input[1].Int()
//zero := l.Type().New() // the zero value
//zero := l.Type().Val.New() // the zero value

// TODO: should we handle overflow by returning zero?
if index > math.MaxInt { // max int size varies by arch
Expand Down
2 changes: 1 addition & 1 deletion lang/core/map/map_lookup_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (obj *MapLookupFunc) Copy() interfaces.Func {
func (obj *MapLookupFunc) Function(ctx context.Context, input []types.Value) (types.Value, error) {
m := (input[0]).(*types.MapValue)
key := input[1]
//zero := m.Type().New() // the zero value
//zero := m.Type().Val.New() // the zero value

val, exists := m.Lookup(key)
if exists {
Expand Down
2 changes: 1 addition & 1 deletion lang/funcs/list_lookup_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (obj *ListLookupFunc) Stream(ctx context.Context) error {

l := (input.Struct()[listLookupArgNameList]).(*types.ListValue)
index := input.Struct()[listLookupArgNameIndex].Int()
zero := l.Type().New() // the zero value
zero := l.Type().Val.New() // the zero value

// TODO: should we handle overflow by returning zero?
if index > math.MaxInt { // max int size varies by arch
Expand Down
2 changes: 1 addition & 1 deletion lang/funcs/map_lookup_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (obj *MapLookupFunc) Stream(ctx context.Context) error {

m := (input.Struct()[mapLookupArgNameMap]).(*types.MapValue)
key := input.Struct()[mapLookupArgNameKey]
zero := m.Type().New() // the zero value
zero := m.Type().Val.New() // the zero value

var result types.Value
val, exists := m.Lookup(key)
Expand Down

0 comments on commit 9a5f6a5

Please sign in to comment.