[go] text/template: update range documentation

0 views
Skip to first unread message

qiu laidongfeng (Gerrit)

unread,
Aug 11, 2026, 9:06:16 PM (6 hours ago) Aug 11
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

qiu laidongfeng has uploaded the change for review

Commit message

text/template: update range documentation

See https://github.com/golang/go/issues/66107#issuecomment-2113163345
resule is "The proposal is to allow range over func and int the same as in Go."

As things stand, this is unfortunate.
I suspect that if we re‑examine the original proposal with today’s perspective,
we will change our existing conclusion. Even now,
it is very easy to alter this (potentially only a CL that change merely one line of
implementation code), but it would break backward compatibility.

This CL to record the current behavior in the documentation.

Update #66107
Update #73282
Change-Id: Ia125ebac9b9a9d86d4ef30f4e593564360dbc607

Change diff

diff --git a/src/text/template/doc.go b/src/text/template/doc.go
index 01b99f0..97e7ee2 100644
--- a/src/text/template/doc.go
+++ b/src/text/template/doc.go
@@ -302,7 +302,8 @@

in which case $index and $element are set to the successive values of the
array/slice index or map key and element, respectively. Note that if there is
-only one variable, it is assigned the element; this is opposite to the
+only one variable, it is assigned the V of any map[K]V type,
+or the first value of any iter.Seq2[E1, E2] type; this is opposite to the
convention in Go range clauses.

A variable's scope extends to the "end" action of the control structure ("if",

Change information

Files:
  • M src/text/template/doc.go
Change size: XS
Delta: 1 file changed, 2 insertions(+), 1 deletion(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ia125ebac9b9a9d86d4ef30f4e593564360dbc607
Gerrit-Change-Number: 813680
Gerrit-PatchSet: 1
Gerrit-Owner: qiu laidongfeng <26454...@qq.com>
Gerrit-Reviewer: qiu laidongfeng <26454...@qq.com>
unsatisfied_requirement
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages