Error if argument to new is not a class.

This commit is contained in:
Bob Nystrom
2014-03-06 06:51:16 -08:00
parent 44e68a5db9
commit 9a959c9eb9
2 changed files with 9 additions and 1 deletions

View File

@ -868,7 +868,13 @@ static bool runInterpreter(WrenVM* vm)
CASE_CODE(NEW):
{
// TODO: Handle object not being a class.
if (!IS_CLASS(PEEK()))
{
STORE_FRAME();
runtimeError(vm, fiber, "Must provide a class to 'new' to construct.");
return false;
}
// Make sure the class stays on the stack until after the instance is
// allocated so that it doesn't get collected.
ObjClass* classObj = AS_CLASS(PEEK());

View File

@ -0,0 +1,2 @@
var a = 123
new a // expect runtime error: Must provide a class to 'new' to construct.