fix: add runtime error when new is called on non-class argument

In the interpreter's NEW opcode handler, check if the top-of-stack value is a class before attempting construction. If not, raise a runtime error with a descriptive message instead of silently failing or crashing.

Also add a test case (test/new_on_nonclass.wren) that verifies the error is correctly triggered when calling new on a non-class value like an integer.
This commit is contained in:
Bob Nystrom
2014-03-06 14:51:16 +00:00
parent b36705d3f3
commit f942da2723
2 changed files with 9 additions and 1 deletions
+2
View File
@@ -0,0 +1,2 @@
var a = 123
new a // expect runtime error: Must provide a class to 'new' to construct.