]> Cypherpunks repositories - gostls13.git/commitdiff
spec: document restrictions for method receivers that are aliases
authorRobert Griesemer <gri@golang.org>
Tue, 19 Nov 2024 04:06:13 +0000 (20:06 -0800)
committerGopher Robot <gobot@golang.org>
Wed, 20 Nov 2024 19:43:54 +0000 (19:43 +0000)
For #70417.

Change-Id: I5e6b3011f356c7ecd8f64f5dcf0a6a77dcb21bbf
Reviewed-on: https://go-review.googlesource.com/c/go/+/629577
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
doc/go_spec.html

index 579e254790df025f5551540fa2ea652dd504c001..31bea3713a7c8248759205f0e57ccc3a1ee271a6 100644 (file)
@@ -1,6 +1,6 @@
 <!--{
        "Title": "The Go Programming Language Specification",
-       "Subtitle": "Language version go1.23 (Oct 1, 2024)",
+       "Subtitle": "Language version go1.24 (Nov 20, 2024)",
        "Path": "/ref/spec"
 }-->
 
@@ -3093,7 +3093,7 @@ to the base type <code>Point</code>.
 </p>
 
 <p>
-If the receiver base type is a <a href="#Type_declarations">generic type</a>, the
+If the receiver base type is a <a href="#Type_definitions">generic type</a>, the
 receiver specification must declare corresponding type parameters for the method
 to use. This makes the receiver type parameters available to the method.
 Syntactically, this type parameter declaration looks like an
@@ -3117,6 +3117,22 @@ func (p Pair[A, B]) Swap() Pair[B, A]  { … }  // receiver declares A, B
 func (p Pair[First, _]) First() First  { … }  // receiver declares First, corresponds to A in Pair
 </pre>
 
+<p>
+If the receiver type is denoted by (a pointer to) an <a href="#Alias_declarations">alias</a>,
+the alias must not be generic and it must not denote an instantiated generic type, neither
+directly nor indirectly via another alias, and irrespective of pointer indirections.
+</p>
+
+<pre>
+type GPoint[P any] = Point
+type HPoint        = *GPoint[int]
+type IPair         = Pair[int, int]
+
+func (*GPoint[P]) Draw(P)   { … }  // illegal: alias must not be generic
+func (HPoint) Draw(P)       { … }  // illegal: alias must not denote instantiated type GPoint[int]
+func (*IPair) Second() int  { … }  // illegal: alias must not denote instantiated type Pair[int, int]
+</pre>
+
 <h2 id="Expressions">Expressions</h2>
 
 <p>