goby-lang / goby

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

Class#singleton_class needs a feature to create a singleton class when it does not have one #589

Closed hachi8833 closed 6 years ago

hachi8833 commented 6 years ago

I found that current Class#singleton_class causes panic when applying to objects other than classes:

Goby 0.1.7 😍 😺 🤤
» "a".singleton_class
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x43d1b35]

goroutine 1 [running]:
github.com/goby-lang/goby/vm.(*RClass).toString(0x0, 0xc4201c2a80, 0xffffffffffffffff)
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/vm/class.go:1205 +0x5
github.com/goby-lang/goby/vm.(*VM).GetREPLResult(0xc4200a6820, 0xc42000ea88, 0x1)
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/vm/repl.go:73 +0x4e
github.com/goby-lang/goby/igb.StartIgb(0x4577b0d, 0x5)
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/igb/repl.go:233 +0xd34
main.main()
    /Users/hachi8833/deve/golang/gopath/sys/src/github.com/goby-lang/goby/goby.go:29 +0x954

According to http://devdocs.io/ruby~2.5/object#method-i-singleton_class:

Returns the singleton class of obj. This method creates a new singleton class if obj does not have one.

The feature to create a new singleton class is missing in current Goby.

st0012 commented 6 years ago

@hachi8833 thanks for reporting. Does this blocks anything?

hachi8833 commented 6 years ago

Not yet so far.

st0012 commented 6 years ago

@saveriomiroddi Can you help me on this?

64kramsystem commented 6 years ago

I think I'm going to be pretty busy for a while with a separate Ruby project :cry: