method `String()` not picked up by compiled code
spolischook opened this issue · 2 comments
spolischook commented
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)
}
cosmos72 commented
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.
spolischook commented
Thanks for explanation