From 6f51febd7696565044d5546aae4032d417ecd0f3 Mon Sep 17 00:00:00 2001 From: Noah Treuhaft Date: Thu, 18 Jun 2026 01:27:41 -0400 Subject: [PATCH] call super.Value.IsMissing instead of checking for nil Calling IsMissing is to check for a missing value is clearer. --- book/src/dev/libraries/go.md | 4 ++-- compiler/semantic/op.go | 2 +- complex_test.go | 2 +- runtime/sam/expr/agg/avg.go | 4 ++-- runtime/sam/expr/eval.go | 2 +- runtime/sam/expr/function/cast.go | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/book/src/dev/libraries/go.md b/book/src/dev/libraries/go.md index 97de13074e..1c74a9e550 100644 --- a/book/src/dev/libraries/go.md +++ b/book/src/dev/libraries/go.md @@ -53,7 +53,7 @@ func main() { return } s := val.Deref("s") - if s == nil { + if s.IsMissing() { s = sctx.Missing().Ptr() } fmt.Println(sup.String(s)) @@ -141,7 +141,7 @@ func main() { return } s := val.Deref("s") - if s == nil { + if s.IsMissing() { s = sctx.Missing().Ptr() } fmt.Println(sup.String(s)) diff --git a/compiler/semantic/op.go b/compiler/semantic/op.go index eb09d697c6..5a0675c993 100644 --- a/compiler/semantic/op.go +++ b/compiler/semantic/op.go @@ -372,7 +372,7 @@ func unmarshalHeaders(val super.Value) (map[string][]string, error) { headers := map[string][]string{} for i, f := range val.Fields() { fieldVal, _ := val.DerefByColumn(i) - if fieldVal == nil { + if fieldVal.IsMissing() { continue } headerStrings, err := decodeStrings(fieldVal) diff --git a/complex_test.go b/complex_test.go index 64e06d363c..03fb272773 100644 --- a/complex_test.go +++ b/complex_test.go @@ -37,7 +37,7 @@ set[1,2,3]` } require.NoError(t, err) v := val.Deref("foo") - require.Nil(t, v) + require.True(t, v.IsMissing()) } } diff --git a/runtime/sam/expr/agg/avg.go b/runtime/sam/expr/agg/avg.go index a7134bb805..aee1a2c2c4 100644 --- a/runtime/sam/expr/agg/avg.go +++ b/runtime/sam/expr/agg/avg.go @@ -41,14 +41,14 @@ const ( func (a *Avg) ConsumeAsPartial(partial super.Value) { sumVal := partial.Deref(sumName) - if sumVal == nil { + if sumVal.IsMissing() { panic(errors.New("avg: partial sum is missing")) } if sumVal.Type() != super.TypeFloat64 { panic(fmt.Errorf("avg: partial sum has bad type: %s", sup.FormatValue(*sumVal))) } countVal := partial.Deref(countName) - if countVal == nil { + if countVal.IsMissing() { panic("avg: partial count is missing") } if countVal.Type() != super.TypeUint64 { diff --git a/runtime/sam/expr/eval.go b/runtime/sam/expr/eval.go index 02b25a37f6..489f1a7245 100644 --- a/runtime/sam/expr/eval.go +++ b/runtime/sam/expr/eval.go @@ -745,7 +745,7 @@ func indexRecordByName(sctx *super.Context, typ *super.TypeRecord, record scode. } field := super.DecodeString(index.Bytes()) val := super.NewValue(typ, record).Ptr().Deref(field) - if val == nil { + if val.IsMissing() { return sctx.Missing() } return *val diff --git a/runtime/sam/expr/function/cast.go b/runtime/sam/expr/function/cast.go index 996e25e75e..995e57b3de 100644 --- a/runtime/sam/expr/function/cast.go +++ b/runtime/sam/expr/function/cast.go @@ -130,7 +130,7 @@ func (c *cast) toRecord(from super.Value, to *super.TypeRecord) (super.Value, bo for i, f := range to.Fields { var val2 super.Value fieldVal := from.Deref(f.Name) // deref(fromRecType, from.Bytes(), f.Name) - if fieldVal == nil { + if fieldVal.IsMissing() { // This field isn't present. If the target type is optional, // code a none value. Otherwise, code error missing. if optionType, _ := super.OptionUnion(f.Type); optionType != nil {