Skip to content

Use native new(value) after the Go 1.26 bump #873

Description

@sean-

Summary

The per-module unexported ptr helper exists only because the new(value) form (constructing a pointer to a non-zero value, e.g. new(false)) requires Go 1.26. The go.mod directive is currently go 1.25.9. Once the floor moves to 1.26, the helper can be deleted and call sites switched to the native form.

Location

opensearch.go:649-656

// ptr returns a pointer to a copy of value. Used for the *T query/body
// parameter pattern. Unexported by design.
//
// Once the module's go directive moves to 1.26, this helper can be deleted
// and call sites can switch to the native new(value) form: new(false).
func ptr[V any](value V) *V {
      return &value
}

and also remove the anonymous function hack: func(i int) *int { return &i }(42) that is peppered throughout the project, too.

Trigger

Gated on bumping the go directive in go.mod from 1.25.9 to 1.26. Note there are per-package ptr definitions across the module (the comment refers to "the unexported ptr defined per-package") — all of them are candidates.

Acceptance criteria

  • Bump go.mod directive to 1.26 (precondition; may be its own PR).
  • Replace ptr(value) call sites with new(value) and delete the per-package ptr helpers.
  • Verify generated code (cmd/osgen) emits new(value) rather than a ptr wrapper, if applicable.
  • No behavior change; purely internal cleanup (not user-facing, no breaking change).

Relationship to other issues

Independent of the ToPointer removal but shares the same Go 1.26 rationale — ToPointer can be removed before this; this one is blocked on the toolchain floor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    dependenciesPull requests that update a dependency filegood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions