thoughts about https://go.dev/blog/loopvar-preview and how to change Go

96 views
Skip to first unread message

Manlio Perillo

unread,
Jan 29, 2024, 6:18:38 AM1/29/24
to golang-nuts
The proposal says:

To ensure backwards compatibility with existing code, the new semantics will only apply  in packages contained in modules that declare go 1.22 or later in their go.mod files. This per-module decision provides developer control of a gradual update to the new semantics throughout a codebase

I think this is not *safe*, since the `go` directive is often not explicitly chosen by the programmer.  An example is when using `go mod init`; I suspect that most users will simply keep the current version.

This is probably not an issue with `loopvar-preview` but it may prevent other language changes.

As an example, suppose someone want to implement support for `error-propagation` (as done by Zig).  In this case the user **must** explicitly declare that he want this feature, so that it (probably) does not count as breaking the Go1 compatibility.

A possible solution is to add a new `feature` field to `go.mod`.  As an example:
```go
feature (
    loopvar
    error-propagation
```

Regards
Manlio Perillo
Reply all
Reply to author
Forward
0 new messages