Yes, I understood the idea from Brian's explanation. Makes adding new
predeclared names (types, literals...) a compatible change.

Thanks.

On Tue, Jan 17, 2023, 04:03 Ian Lance Taylor <i...@golang.org> wrote:

> On Mon, Jan 16, 2023 at 5:46 PM 'wagner riffel' via golang-nuts
> <golang-nuts@googlegroups.com> wrote:
> >
> > On 1/13/23 07:20, Gorka Guardiola wrote:
> > > According to the spec it seems like it is legal to shadow a type with a
> > > variable, even a builtin type.
> > > Is there any specific rationale for this? I guess that it makes scoping
> > > checks easier and faster, but still.
> > >
> >
> > I don't think there is any special rationale behind it, in Go builtin
> > types are predefined identifiers, not keywords as usual in other
> > languages, thus those follow rules of identifiers, not keywords.
> > Although it feels astonishing that you can shadow even predefined
> > constants like "true := false", in my experience this haven't shown to
> > be an issue.
>
> There is a rationale: we can add new predeclared identifiers without
> breaking existing working code.
>
> For example, the Go 1.18 release added two new predeclared
> identifiers: `any` and `comparable`.  Because they were predeclared
> identifiers, not keywords, existing code that used them as variable
> names continued to work.
>
> Ian
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CACm3i_hbKDGq_WObfN1RHp2nC81%2B6QbsudASP7txpnsMT_UEEw%40mail.gmail.com.

Reply via email to