diff options
| author | Robert Griesemer <gri@google.com> | 2026-04-09 13:18:59 -0700 |
|---|---|---|
| committer | Robert Griesemer <gri@google.com> | 2026-04-09 14:33:22 -0700 |
| commit | 2393d14061ea07d26be70091196bbe7c8c12a402 (patch) | |
| tree | 6d6b676153802414d304ec7e1a5190bc36e72462 | |
| parent | cca91cc00c68d5c278901eeeb1b13a0691173e39 (diff) | |
| download | go-2393d14061ea07d26be70091196bbe7c8c12a402.tar.xz | |
spec: move rule for type parameters up in section of range clause
Make the rule for range expressions of type parameter type more
visible by moving it up (it was easily missed before as it was
at the end of the example section).
Add a corresponding example to the examples.
Per suggestion from @adonovan.
Change-Id: I8527e69ecc7d0110554ba00f4c30829f7d260d41
Reviewed-on: https://go-review.googlesource.com/c/go/+/764921
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
| -rw-r--r-- | doc/go_spec.html | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/doc/go_spec.html b/doc/go_spec.html index 6cc64d7a19..a2c1e899e4 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -6835,6 +6835,13 @@ If the loop body terminates (such as by a <code>break</code> statement), </ol> <p> +If the type of the range expression is a <a href="#Type_parameter_declarations">type parameter</a>, +all types in its type set must have the same underlying type and the range expression must be valid +for that type, or, if the type set contains channel types, it must only contain channel types with +identical element types, and all channel types must permit receive operations. +</p> + +<p> The iteration variables may be declared by the "range" clause using a form of <a href="#Short_variable_declarations">short variable declaration</a> (<code>:=</code>). @@ -6938,14 +6945,16 @@ var t Tree[string, int] for k, v := range t.Walk { // process k, v } -</pre> -<p> -If the type of the range expression is a <a href="#Type_parameter_declarations">type parameter</a>, -all types in its type set must have the same underlying type and the range expression must be valid -for that type, or, if the type set contains channel types, it must only contain channel types with -identical element types, and all channel types must permit receive operations. -</p> +// xor returns the xor-ed bytes of S +func xor[S ~[]byte](s S) byte { + var r byte + for _, b := range s { + r ^= b + } + return r +} +</pre> <h3 id="Go_statements">Go statements</h3> |
