wren-lang / wren

The Wren Programming Language. Wren is a small, fast, class-based concurrent scripting language.
http://wren.io
MIT License
6.86k stars 550 forks source link

SegFault when overridding toString #67

Closed Calamari closed 9 years ago

Calamari commented 9 years ago

Hello.

Just getting warm with the wren language, and I must say: It's neat. I just do useless playaround stuff with it, and came across the following problem:

When you try running the following "program" you will get a Segmentation Fault: 11.

class My {
  toString { 3 }
}

var my = new My

IO.print(my)

Of course the problem is, that I return a non-string in the toString method, if I would write { "3"} then all would work as expected. Still, I think there should be a warning or error raised, and not abort with a SegFault.

What do you think?

munificent commented 9 years ago

Yes, this is totally a bug!

It's coming from a limitation in the current still-very-much-in-progress embedding API. Right now, the API doesn't give you a way to generate a runtime error, which is what it should do when the result of toString isn't a string.

Thanks for filing this!