JoeStrout / miniscript

source code of both C# and C++ implementations of the MiniScript scripting language
MIT License
280 stars 64 forks source link

Disallow new with any non-map argument #104

Closed JoeStrout closed 8 months ago

JoeStrout commented 11 months ago

Right now you can do new "foo" or new 42 or new null, and you get back a map with __isa set to the argument. But this is a weird map that does not have access to the standard map methods; and doing isa tests on this produces inconsistent results between the C# and C++ implementations. The resulting beast is just plain weird (and even weirder if you used a funcRef or NaN as your argument!), and it's difficult to decide how it ought to behave, or why you would ever have a valid use for it.

So, let's just throw a runtime error if you use new with any argument that is not a map. If you manually assign to __isa, well, we probably can't stop you (without impacting all map-entry assignments) — but we should explicitly document that the resulting behavior is undefined.

JoeStrout commented 11 months ago

...While we're at it, think about what we should do if some confused user does new string, new list, or new funcRef. Unless they're just poking the edges of the language on purpose, this is almost certainly an error.

juh9870 commented 11 months ago

Would be good to throw informative error, akin to