lang: core, funcs: Use the correct zero type

I wasn't using the correct contained type here.
This commit is contained in:
James Shubin
2024-08-19 00:46:23 -04:00
parent 2e774215e4
commit 9a5f6a5bd3
4 changed files with 4 additions and 4 deletions

View File

@@ -232,7 +232,7 @@ func (obj *ListLookupFunc) Copy() interfaces.Func {
func (obj *ListLookupFunc) Function(ctx context.Context, input []types.Value) (types.Value, error) { func (obj *ListLookupFunc) Function(ctx context.Context, input []types.Value) (types.Value, error) {
l := (input[0]).(*types.ListValue) l := (input[0]).(*types.ListValue)
index := input[1].Int() 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? // TODO: should we handle overflow by returning zero?
if index > math.MaxInt { // max int size varies by arch if index > math.MaxInt { // max int size varies by arch

View File

@@ -234,7 +234,7 @@ func (obj *MapLookupFunc) Copy() interfaces.Func {
func (obj *MapLookupFunc) Function(ctx context.Context, input []types.Value) (types.Value, error) { func (obj *MapLookupFunc) Function(ctx context.Context, input []types.Value) (types.Value, error) {
m := (input[0]).(*types.MapValue) m := (input[0]).(*types.MapValue)
key := input[1] key := input[1]
//zero := m.Type().New() // the zero value //zero := m.Type().Val.New() // the zero value
val, exists := m.Lookup(key) val, exists := m.Lookup(key)
if exists { if exists {

View File

@@ -186,7 +186,7 @@ func (obj *ListLookupFunc) Stream(ctx context.Context) error {
l := (input.Struct()[listLookupArgNameList]).(*types.ListValue) l := (input.Struct()[listLookupArgNameList]).(*types.ListValue)
index := input.Struct()[listLookupArgNameIndex].Int() 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? // TODO: should we handle overflow by returning zero?
if index > math.MaxInt { // max int size varies by arch if index > math.MaxInt { // max int size varies by arch

View File

@@ -189,7 +189,7 @@ func (obj *MapLookupFunc) Stream(ctx context.Context) error {
m := (input.Struct()[mapLookupArgNameMap]).(*types.MapValue) m := (input.Struct()[mapLookupArgNameMap]).(*types.MapValue)
key := input.Struct()[mapLookupArgNameKey] key := input.Struct()[mapLookupArgNameKey]
zero := m.Type().New() // the zero value zero := m.Type().Val.New() // the zero value
var result types.Value var result types.Value
val, exists := m.Lookup(key) val, exists := m.Lookup(key)