Skip to content

add ?? and ?. operators - #7249

Merged
mccanne merged 2 commits into
mainfrom
none-ops
Aug 26, 2026
Merged

add ?? and ?. operators#7249
mccanne merged 2 commits into
mainfrom
none-ops

Conversation

@mccanne

@mccanne mccanne commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

This commit adds preliminary support for dealing with option types. The ?? is the none-ish coalescing operator and ?. is the optional chaining operator similar to typescript.

In subsequent commits, we will add Comprehensive type checking with respect to option types and runtime logic that will generate structured errors when none values are encountered instead of error("missing").

This commit adds preliminary support for dealing with option types.
The ?? is the none-ish coalescing operator and ?. is the optional chaining
operator similar to typescript.

In subsequent commits, we will add Comprehensive type checking with respect
to option types and runtime logic that will generate structured errors when
none values are encountered instead of error("missing").
Comment thread compiler/semantic/schema.go Outdated
if table == "" || s.table == table {
for _, col := range s.typ.Fields {
out = append(out, sem.NewThis(n, append(slices.Clone(path), col.Name)))
path := sem.NewPath(append(slices.Clone(path), col.Name)...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
path := sem.NewPath(append(slices.Clone(path), col.Name)...)
path := append(sem.NewPath(path...), sem.PathElem{ID: col.Name})

Comment thread runtime/vam/expr/function/coalesce.go Outdated
Comment on lines 92 to 94
case *vector.None:
return true
case *vector.Null:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: None comes after null.

Suggested change
case *vector.None:
return true
case *vector.Null:
case *vector.Null:
return true
case *vector.None:

Comment thread runtime/vam/expr/recordexpr.go Outdated
if !super.IsOptionType(u.Type()) {
return u
}
v := u.Normalized()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We usually say vec.

Suggested change
v := u.Normalized()
vec := u.Normalized()

Comment thread vector/apply.go Outdated
}
d := u.Dynamic()
vecs := make([]Any, 0, len(d.Values))
for _, v := range d.Values {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
for _, v := range d.Values {
for _, vec := range d.Values {

Comment thread vector/union.go Outdated

func (u *Union) IsNormalizedOption() bool {
var cnt int
for _, v := range u.Values() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
for _, v := range u.Values() {
for _, vec := range u.Values() {

@mccanne
mccanne merged commit 68a28c5 into main Aug 26, 2026
2 checks passed
@mccanne
mccanne deleted the none-ops branch August 26, 2026 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants