neugram / ng

scripting language integrated with Go
https://neugram.io
BSD 2-Clause "Simplified" License
916 stars 43 forks source link

ng/eval: defer outside a function scope #210

Closed sbinet closed 6 years ago

sbinet commented 6 years ago

right now, when doing this (in Jupyter or directly in ng) one gets:

ng> import "os"
ng> f, err := os.Create("foo")
ng> if err != nil { panic(err) }
ng> defer f.Close()
ng: defer outside a function scope

as mentioned here we should probably put all the top-level code insider a "fake" "ng-main" function scope so we get a defer-context to hang all the top-level defers on to.

what do you think @crawshaw ? would this break something somewhere? (go test ./... didn't complain)