x-motemen / gore

Yet another Go REPL that works nicely. Featured with line editing, code completion, and more.
MIT License
5.11k stars 148 forks source link

An undefined bug? #189

Closed iaxax closed 2 years ago

iaxax commented 4 years ago

undefined

itchyny commented 4 years ago

This is surely a surprising behavior. Currently gore tries to 1. parse the input as an expression, 2. parse as a declaration in the main function 3. declaration outside the main function. The struct declaration in the main function is allowed in Go so the input generates the following code. But maybe we can fix this without breaking other behaviors.

package main

func main() { type A struct{ v int } }
func foo(a A)   { a.v = 2 }
xiantang commented 2 years ago

https://github.com/x-motemen/gore/issues/34#issuecomment-991494511 struct method also cannot define...

xiantang commented 2 years ago

can we define struct out side the main function. then struct method and function reference costom struct can use correct. will it be breaking change?

xiantang commented 2 years ago

image I have support this in my side

xiantang commented 2 years ago

can try my version https://github.com/xiantang/gore.. I have supported method and pointer function for struct, but dont know whether it's a breaking change.. if you want use this feature can clone my fork than make install

@itchyny

itchyny commented 2 years ago

This has been resolved in v0.5.5.