Go version
go version go1.23.0 linux/amd64
Output of go env
in your module/workspace:
Go playground
What did you do?
Casting a string to any
and passing it to unique.Make
seems to cause issues.
package main
import "unique"
func main() {
unique.Make(any(""))
}
Example crash 1 unexpected fault address 0x912c08
: https://go.dev/play/p/vZWwiXU6YXL
Example crash 2 panic: interface conversion: interface {} is *unique.uniqueMap[string], not *unique.uniqueMap[interface {}]
: https://go.dev/play/p/U8JvXsqXpJQ
What did you see happen?
For it not to crash
What did you expect to see?
I expected to see nothing and the program not to crash
Comment From: gabyhelp
Related Issues and Documentation
- go/types, types2: go generic assert compile escape #52228 (closed)
- cmd/compile/internal/types2: panic when type function selector is not instantiated #48048 (closed)
- go/types: crash in assignment between "unexported" named interface types #5512 (closed)
- runtime: SIGBUS in initItab (write to readonly ITab.Fun) on unchecked type assertion with generics #65962 (closed)
- go/types, govet: panics when encountering (string constant) + string(rune constant) #4982 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: ianlancetaylor
CC @mknyszek
Comment From: mknyszek
Looking into it.
Comment From: mknyszek
I see the general problem -- it's a classic reflection mistake when trying to get the type of a value (via TypeOf
). This package doesn't use reflection directly, but does something reflect-like to extract the type.
Easy fix, apologies for the breakage.
Comment From: gopherbot
Change https://go.dev/cl/607355 mentions this issue: unique: use TypeFor instead of TypeOf to get type in Make
Comment From: mknyszek
@gopherbot Please open a backport issue for Go 1.23.
This problem accidentally limits what types the unique
package can work with, and results in panics. Also, the fix is very simple and low risk.
Comment From: gopherbot
Backport issue(s) opened: #68992 (for 1.23).
Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.
Comment From: ALX99
Appreciate the insanely quick response. Thank you for your contributions to Go!
Comment From: gopherbot
Change https://go.dev/cl/607435 mentions this issue: [release-branch.go1.23] unique: use TypeFor instead of TypeOf to get type in Make