goby-lang / goby

Goby - Yet another programming language written in Go
MIT License
3.49k stars 171 forks source link

`File#size` causes panic on nonexistent filename #281

Closed hachi8833 closed 7 years ago

hachi8833 commented 7 years ago

Checked with REPL and normal execution.

require "file"
puts(File.size("file.gb"))

Running:

goby tmp.gb
.gb
["/home/goby/", "test.sh"]
home/goby/test.sh
Internal Error: stat /Users/hachi8833/deve/goby/file.gb: no such file or directory
panic: stat /Users/hachi8833/deve/goby/file.gb: no such file or directory [recovered]
    panic: stat /Users/hachi8833/deve/goby/file.gb: no such file or directory

goroutine 1 [running]:
github.com/goby-lang/goby/vm.(*thread).execInstruction.func1(0xc42010a030)
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/vm/thread.go:71 +0x81
panic(0x1330820, 0xc4201234a0)
    /usr/local/opt/go/libexec/src/runtime/panic.go:489 +0x2cf
github.com/goby-lang/goby/vm.builtinFileClassMethods.func8.1(0xc42010a030, 0xc420107fa0, 0x1, 0x1, 0x0, 0xc420107fa0, 0x0)
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/vm/file.go:227 +0x23c
github.com/goby-lang/goby/vm.(*thread).evalBuiltInMethod(0xc42010a030, 0x15169a0, 0xc420075140, 0xc42010edc0, 0x5, 0x1, 0x6, 0x0)
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/vm/thread.go:130 +0x202
github.com/goby-lang/goby/vm.glob..func21(0xc42010a030, 0xc420108d20, 0xc42010ec20, 0x2, 0x2)
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/vm/instruction.go:368 +0x397
github.com/goby-lang/goby/vm.(*thread).execInstruction(0xc42010a030, 0xc420108d20, 0xc42010b860)
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/vm/thread.go:75 +0x96
github.com/goby-lang/goby/vm.(*thread).evalCallFrame(0xc42010a030, 0xc420108d20)
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/vm/thread.go:42 +0x60
github.com/goby-lang/goby/vm.(*thread).startFromTopFrame(0xc42010a030)
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/vm/thread.go:36 +0x55
github.com/goby-lang/goby/vm.(*VM).startFromTopFrame(0xc4200241b0)
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/vm/vm.go:190 +0x2f
github.com/goby-lang/goby/vm.(*VM).ExecInstructions(0xc4200241b0, 0xc42000e0b0, 0x1, 0x1, 0x7fff5fbfe46d, 0x6)
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/vm/vm.go:129 +0x764
main.main()
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/goby.go:66 +0x355
st0012 commented 7 years ago

This should be fixed in #284