gopherdata / gophernotes

The Go kernel for Jupyter notebooks and nteract.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

method `String()` not picked up by compiled code

spolischook opened this issue · comments

There is an example of code snippet that have different result of go run and gophernotes:

type Direction int

const (
	North Direction = iota
	East
	South
	West
)

func (d Direction) String() string {
	return [...]string{"North", "East", "South", "West"}[d]
}

func main() {
	fmt.Print(East)
}

gophernotes example:
Selection_412

go run example:
Selection_413

This has the same root cause as #225
i.e. new named types created by the interpreter are emulated,
and their methods - in this case Direction.toString() - are visible only by interpreted code.

It's also equally unfixable, at least until Go standard library provides a mechanism
to create new named types at runtime and attach methods to them.

A partial workaround is to replace fmt.Print(East) with fmt.Println(East.String())

[UPDATE] I have added this limitation to the relevant section in the main README.md.

Thanks for explanation