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

Using maps with uncomparable keys #24

Open
go-li opened this issue Aug 1, 2018 · 2 comments
Open

Using maps with uncomparable keys #24

go-li opened this issue Aug 1, 2018 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@go-li
Copy link

go-li commented Aug 1, 2018

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.

@go-li
Copy link
Author

go-li commented Aug 1, 2018

On a second consideration it works as expected

https://play.folang.org/p/-iokGIXkfJ9

@go-li go-li closed this as completed Aug 1, 2018
@albrow albrow reopened this Aug 3, 2018
@albrow
Copy link
Owner

albrow commented Aug 3, 2018

It might not be obvious, but the second playground link you shared shows an error coming from the Go compiler. Re-opening this because I would like the Fo compiler to catch this type of issue instead of generating invalid code and relying on the Go compiler to catch it.

(The Fo compiler works by transforming the AST into pure Go code and then calling the Go compiler).

@albrow albrow added the bug Something isn't working label Aug 3, 2018
@albrow albrow self-assigned this Aug 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants