mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 14:18:42 +01:00
Error if argument to new is not a class.
This commit is contained in:
@ -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());
|
||||
|
||||
2
test/new_on_nonclass.wren
Normal file
2
test/new_on_nonclass.wren
Normal file
@ -0,0 +1,2 @@
|
||||
var a = 123
|
||||
new a // expect runtime error: Must provide a class to 'new' to construct.
|
||||
Reference in New Issue
Block a user