gopherdata / gophernotes

The Go kernel for Jupyter notebooks and nteract.
MIT License
3.83k stars 264 forks source link

Type inference on composite literals #90

Closed dyllanwli closed 6 years ago

dyllanwli commented 6 years ago

Define a map and the cell returns an error:

var p = map[string][]string{"world":{"hello"}}
runtime error: invalid memory address or nil pointer dereference

But if I define a empty map and it will not raise a panic.

var p = map[string][]string{} // correct.

Why this error happened? Could anyone help me to fix that?

SpencerPark commented 6 years ago

This is an issue with the underlying interpreter gomacro. The interpreter doesn't have support for the type inference that the go compiler performs on composite literals like this. The solution until that is implemented is to simply include the type when writing the literal:

var p = map[string][]string{"world":[]string{"hello"}}

I've opened up an issue cosmos72/gomacro#9 related to this over at gomacro.

dwhitena commented 6 years ago

Thanks @SpencerPark!

dwhitena commented 6 years ago

I updated the title of this issue to track this on our side.

cosmos72 commented 6 years ago

fixed upstream, see https://github.com/cosmos72/gomacro/issues/9 and https://github.com/cosmos72/gomacro/commit/75e1b439420802d760132f33b30e456e928dbbc6