Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Go 1.22 unalias #3471

Merged
merged 1 commit into from
Jan 7, 2025
Merged

Use Go 1.22 unalias #3471

merged 1 commit into from
Jan 7, 2025

Conversation

StevenACoffman
Copy link
Collaborator

@StevenACoffman StevenACoffman commented Jan 7, 2025

Go 1.22 Added types.Unalias per https://tip.golang.org/doc/go1.22

However, when #3226 and then #3246 was added, we added a variety of Go 1.23-only build-tagged code that we were supposed to remove when we dropped support for Go 1.22. However, types.Unalias should never have been Go 1.23 only. Go 1.23 Added generic type aliases which is a different thing than Go 1.9's type aliases.

In Go 1.9+ you can have a type alias:

type Alias = someType

but Go in 1.23 we can also declare type parameters with the alias declaration:

type Alias[P1 C1, P2 C2] = someType

Importantly, Go 1.18 introduced any as a type alias for interface{}, and we want to encourage the use of any. Since any is a type alias of interface{} it is causing some confusion (and non-repeatable results) when we do not use types.Unalias in Go 1.22.

From Alias names

Go 1.9 introduced the notion of a type alias. A type alias provides a new name for an existing type without introducing a new type that has a different identity.

In contrast to a regular type definition

type T T0

which declares a new type that is never identical to the type on the right-hand side of the declaration, an alias declaration

type A = T  // the "=" indicates an alias declaration

declares only a new name A for the type on the right-hand side: here, A and T denote the same and thus identical type T.

Signed-off-by: Steve Coffman <steve@khanacademy.org>
@coveralls
Copy link

Coverage Status

coverage: 73.855% (-0.06%) from 73.915%
when pulling a7e6470 on unalias_go122
into 6d7a5d9 on master.

@StevenACoffman
Copy link
Collaborator Author

@UnAfraid @a8m @giautm @evellior Possibly fixes #3414

@StevenACoffman StevenACoffman merged commit 630f3e9 into master Jan 7, 2025
18 checks passed
@StevenACoffman StevenACoffman deleted the unalias_go122 branch January 7, 2025 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants