aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Li <simonsli@meta.com>2026-02-18 16:12:31 +0000
committerGopher Robot <gobot@golang.org>2026-03-23 11:29:24 -0700
commit943235a5e5f333db25e1675f68ea61416909b6a4 (patch)
tree4709e97b10887943e19684f8cd4baa634f846c5c
parent1a44be4cecdc742ac6cce9825f9ffc19857c99f3 (diff)
downloadgo-943235a5e5f333db25e1675f68ea61416909b6a4.tar.xz
[release-branch.go1.26] builtin: update new function comment
The function comment for new does not reflect the recent change in behaviour since Go 1.26. For #77584. For #77586. Change-Id: I501d701adb5a1c2ff4b559c243ba07bbef4940d9 Reviewed-on: https://go-review.googlesource.com/c/go/+/746561 Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Michael Podtserkovskii <michaelpo@meta.com> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> (cherry picked from commit 8d5e57474c4fe6d653327a49d460d4010c1d1d9b) Reviewed-on: https://go-review.googlesource.com/c/go/+/758220 Auto-Submit: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
-rw-r--r--src/builtin/builtin.go18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/builtin/builtin.go b/src/builtin/builtin.go
index afa2a10f90..eea9004842 100644
--- a/src/builtin/builtin.go
+++ b/src/builtin/builtin.go
@@ -122,6 +122,10 @@ type Type int
// invocation.
type Type1 int
+// TypeOrExpr is here for the purposes of documentation only. It is a stand-in
+// for either a Go type or an expression.
+type TypeOrExpr int
+
// IntegerType is here for the purposes of documentation only. It is a stand-in
// for any integer type: int, uint, int8 etc.
type IntegerType int
@@ -220,10 +224,16 @@ func max[T cmp.Ordered](x T, y ...T) T
// min will return NaN.
func min[T cmp.Ordered](x T, y ...T) T
-// The new built-in function allocates memory. The first argument is a type,
-// not a value, and the value returned is a pointer to a newly
-// allocated zero value of that type.
-func new(Type) *Type
+// The built-in function new creates a new, initialized variable and returns
+// a pointer to it. It accepts a single argument, which may be either a type
+// or an expression.
+//
+// If the argument is a type T, then new(T) allocates a variable of type T
+// initialized to its zero value.
+//
+// If the argument is an expression x, then new(x) allocates a variable of
+// the type of x initialized to the value of x.
+func new(TypeOrExpr) *Type
// The complex built-in function constructs a complex value from two
// floating-point values. The real and imaginary parts must be of the same