From 5c7d8a3e4896df7d2d0f9d9ec72248eb39e71f96 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 25 Feb 2026 15:35:48 -0800 Subject: [PATCH] builtin: incorporate all feedback into doc string for new The previously submitted CL didn't include some of the feedback that was provided on the CL. Specifically, it didn't mention the behavior of `new` for untyped constant arguments. For #77584. Change-Id: I1668a79a655246e5a55a4741a6c564b7dd6707c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/749061 Reviewed-by: Robert Griesemer Reviewed-by: Dmitri Shuralyov Reviewed-by: Alan Donovan LUCI-TryBot-Result: Go LUCI --- src/builtin/builtin.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/builtin/builtin.go b/src/builtin/builtin.go index eea9004842..be53077d9c 100644 --- a/src/builtin/builtin.go +++ b/src/builtin/builtin.go @@ -224,15 +224,14 @@ 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 built-in function new creates a new, initialized variable and returns +// The built-in function new allocates 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. +// Otherwise, the argument is an expression x and new(x) allocates a variable +// of the type of x initialized to the value of x. If that value is an untyped +// constant, it is first implicitly converted to its default type. func new(TypeOrExpr) *Type // The complex built-in function constructs a complex value from two