Check argument type in new Fn.
This commit is contained in:
@@ -1456,9 +1456,6 @@ static void methodCall(Compiler* compiler, Code instruction,
|
|||||||
|
|
||||||
Compiler fnCompiler;
|
Compiler fnCompiler;
|
||||||
initCompiler(&fnCompiler, compiler->parser, compiler, true);
|
initCompiler(&fnCompiler, compiler->parser, compiler, true);
|
||||||
|
|
||||||
// TODO: Allow newline between '{' and '|'?
|
|
||||||
|
|
||||||
fnCompiler.numParams = parameterList(&fnCompiler, NULL, NULL,
|
fnCompiler.numParams = parameterList(&fnCompiler, NULL, NULL,
|
||||||
TOKEN_PIPE, TOKEN_PIPE);
|
TOKEN_PIPE, TOKEN_PIPE);
|
||||||
|
|
||||||
@@ -2561,8 +2558,6 @@ static void classDefinition(Compiler* compiler)
|
|||||||
|
|
||||||
// Compile the method definitions.
|
// Compile the method definitions.
|
||||||
consume(compiler, TOKEN_LEFT_BRACE, "Expect '{' after class declaration.");
|
consume(compiler, TOKEN_LEFT_BRACE, "Expect '{' after class declaration.");
|
||||||
|
|
||||||
// TODO: Should newline be required here?
|
|
||||||
matchLine(compiler);
|
matchLine(compiler);
|
||||||
|
|
||||||
while (!match(compiler, TOKEN_RIGHT_BRACE))
|
while (!match(compiler, TOKEN_RIGHT_BRACE))
|
||||||
|
|||||||
+5
-1
@@ -308,7 +308,11 @@ DEF_NATIVE(fn_instantiate)
|
|||||||
|
|
||||||
DEF_NATIVE(fn_new)
|
DEF_NATIVE(fn_new)
|
||||||
{
|
{
|
||||||
// TODO: Validate arg type.
|
if (!IS_FN(args[1]) && !IS_CLOSURE(args[1]))
|
||||||
|
{
|
||||||
|
RETURN_ERROR("Argument must be a function.");
|
||||||
|
}
|
||||||
|
|
||||||
// The block argument is already a function, so just return it.
|
// The block argument is already a function, so just return it.
|
||||||
RETURN_VAL(args[1]);
|
RETURN_VAL(args[1]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
new Fn(3) // expect runtime error: Argument must be a function.
|
||||||
Reference in New Issue
Block a user