On Wed, Jun 17, 2020 at 5:18 PM Randall O'Reilly <
rcore...@gmail.com> wrote:
>
> Good point!
>
> I can think of 2 possible (non-mutex) solutions:
>
> * Use an explicit type expression to refer to the type: `type(ms.T)` and the field is just `ms.T`
>
> * Within the method scope, make `T` a valid type name, so you can just use `T` directly -- this might even be preferable overall as it is simpler, and should be clear what you're referring to in that context. May still need `ms.T` and `type(ms.T)` variants to refer to the type parameters outside of the method scope (being able to do so might make some type linkages across interface types simpler -- haven't worked that through at all..)
An earlier version of the design let people refer to type parameters
of the type without requiring them to be declared with the receiver.
But that meant that an identifier in a method was looked up first in
the method, then in the type parameters of the receiver, then in the
package. People found that additional scope rather confusing. It
wasn't completely obvious what would happen if the same name appears
as a package scope variable and as a receiver's type parameter.
Using ms.T avoids that problem but as observed it leads to a different
ambiguity. If we were to use that approach I think we would have to
forbid using the same name for a type parameter, a field, and a
method. But that would in turn make it hard to embed a type
parameter.
Ian
> To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/3CC5CE67-BE33-40B4-9C84-371ADD69D729%40gmail.com.