From: Robert Griesemer Date: Tue, 19 Nov 2024 04:06:13 +0000 (-0800) Subject: spec: document restrictions for method receivers that are aliases X-Git-Tag: go1.24rc1~183 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e0b569842d0ef5deed5c455eef001b02aec27934;p=gostls13.git spec: document restrictions for method receivers that are aliases For #70417. Change-Id: I5e6b3011f356c7ecd8f64f5dcf0a6a77dcb21bbf Reviewed-on: https://go-review.googlesource.com/c/go/+/629577 Auto-Submit: Robert Griesemer TryBot-Bypass: Robert Griesemer Reviewed-by: Ian Lance Taylor Reviewed-by: Robert Griesemer --- diff --git a/doc/go_spec.html b/doc/go_spec.html index 579e254790..31bea3713a 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -3093,7 +3093,7 @@ to the base type Point.

-If the receiver base type is a generic type, the +If the receiver base type is a generic type, 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 +

+If the receiver type is denoted by (a pointer to) an alias, +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. +

+ +
+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]
+
+

Expressions