cmd/compile: typechecker Go version and build-constraints Go version disagree #58342
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
go.mod
:main.go
:go118.go
:go120.go
:What did you expect to see?
I expected the program to successfully compile with either Go 1.18 or Go 1.20, offering stricter type-safety with Go 1.20.
While this flexibility isn't such a problem for standalone programs (as in the above reproducer), this is a problem for me trying to publish a library where I need the type parameter to be spec-comparable; for Go <1.20 it is appropriate to fall back to
any
and note in the documentation that it may panic if the type isn't spec-comparable; while for Go >=1.20 it is appropriate for the compiler to help check for mistakes and prevent non-spec-comparable type parameters.If that example doesn't demonstrate the use-case to you, consider a library providing a
type MyMap[K mapkey, v Any] struct{ … }
withtype mapkey = any
forgo:build !go1.20
andtype mapkey = comparable
forgo:build go1.20
.I'll note that there was no mention of build-constraints in #56548. I'm not entirely sure how I think this should work, but I think that satisfying the
go1.20
build constraint while disabling Go 1.20 features is definitely wrong.What did you see instead?
The program fails to compile with Go 1.20:
The text was updated successfully, but these errors were encountered: