Skip to content
This repository was archived by the owner on Sep 20, 2022. It is now read-only.
This repository was archived by the owner on Sep 20, 2022. It is now read-only.

Using maps with uncomparable keys #24

Description

@go-li

Hello, the following does not run
https://play.folang.org/p/XhaheZsrxBT

package main

func instantiate[T](p *T) {
	var foo = make(map[T]int)
	foo[*p] = 9
}

func main() {
	instantiate[[0]byte]((*[0]byte)(nil))
}

The expected result that creation of a map with uncomparable keys is either caught at compile time, or it blows up gracefully during map creation time. Currently it does:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0xffffffff addr=0x0 pc=0x841cb]

goroutine 1 [running]:
main.instantiate___0_byte(...)
	/tmp/sandbox652760664/main.go:5
main.main()
	/tmp/sandbox652760664/main.go:9 +0x6b

An engineering decision how to handle incomparable map keys is needed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions