-3

Among many new things in the recent proposal about adding generic programming for Golang there is a new keyword any

So if my current program has declared a variable named any it won't compile.

Bakurits
  • 402
  • 3
  • 11
  • 1
    It's targeted at Go2, which mean it does not have to be backward-compatible. It's just a proposal right now though, so it's subject to change before release. – Adrian Jan 13 '21 at 14:37
  • 1
    `any` will not be a keyword. Read the proposal properly, it is predeclared. – Volker Jan 13 '21 at 14:38
  • 2
    @Adrian "If the proposal is accepted, our goal will be to have a complete, though perhaps not fully optimized, implementation for people to try by the end of the year, perhaps as part of the Go 1.18 betas." – Bakurits Jan 13 '21 at 14:40
  • 2
    If it's accepted into a go1.x release, then by definition it's backwards compatible. – JimB Jan 13 '21 at 14:42
  • That's why I'm asking. How is it possible? @Volker can you elaborate? – Bakurits Jan 13 '21 at 14:44
  • 2
    I'm not entirely sure why this question is downoted and closed. It's a reasonable question to ask. The answer is two fold: first, YES it's backwards compatible -- the proposal says this explicitly. Twice. (https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#values-of-type-parameters-are-not-boxed). As for the *how does this work with any* question, Volker's answer below addresses that. – Eli Bendersky Jan 20 '21 at 04:35

1 Answers1

3

in the recent proposal about adding generic[s ...] there is a new keyword any.

Wrong. any will be a predaclared identifier not a keyword.

So if my current program has declared a variable named any it won't compile.

No, of course not, it will just redeclare any in the current scope.

The list of keywords in Go is pretty short, see https://golang.org/ref/spec#Keywords . Keywords are keywords and cannot be used for other things. A predeclared identifier (see https://golang.org/ref/spec#Predeclared_identifiers) is not a keyword and can be redeclared.

Volker
  • 40,468
  • 7
  • 81
  • 87