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
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",
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |