-
-
Couldn't load subscription status.
- Fork 396
Description
Go 1.22 introduced the types.Alias type, but did not start creating instances of them, unless GODEBUG=gotypesalias=1. Go 1.23 will start creating instances of them, unless GODEBUG=gotypesalias=0. The effective default value of GODEBUG is determined by the version of the go directive in the go.mod file of the application. It is inevitably an incompatible change.
Staticcheck will need to handle types.Alias values. In most cases, it is sufficient to ensure that every type switch and type assertion that tests for a particular types.Type removes any Alias constructors, either by calling Unalias or Underlying as the situation requires. (You may find this package useful during the transition.) In some cases, for example when a name or source location is required, the application can do a better job by not discarding aliases, but handling them with additional logic.
You may find it helpful to:
- look at some of the CLs attached to the issues below to get a feel for what is involved;
- run the analyzer in https://go.dev/cl/575057, which detects all the type switches and assertions that need to be audited;
- set up an additional CI (e.g. GitHub Actions) build with GODEBUG=gotypesalias=1.
Let us know if we can help.
(In due course, aliases will support type parameters, like Named types. We expect this change will be straightforward since it is compatible.)
Related:
- x/tools/gopls: handle go1.22's go/types.Alias golang/go#64581
- x/tools: get tests passing with GODEBUG=gotypesalias=1 golang/go#65294
cc @findleyr