Fixed chained functions, resolved #52

This commit is contained in:
2023-06-14 17:41:30 +10:00
parent f25f389b4e
commit 1481216e69
3 changed files with 32 additions and 6 deletions

View File

@@ -1229,12 +1229,8 @@ static bool execFnCall(Toy_Interpreter* interpreter, bool looseFirstArgument) {
//get the function literal //get the function literal
Toy_Literal func = identifier; Toy_Literal func = identifier;
if (!TOY_IS_FUNCTION(func) && Toy_parseIdentifierToValue(interpreter, &func)) {
if (!Toy_parseIdentifierToValue(interpreter, &func)) {
Toy_freeLiteralArray(&arguments);
Toy_freeLiteral(stackSize);
Toy_freeLiteral(identifier); Toy_freeLiteral(identifier);
return false;
} }
if (!TOY_IS_FUNCTION(func) && !TOY_IS_FUNCTION_NATIVE(func)) { if (!TOY_IS_FUNCTION(func) && !TOY_IS_FUNCTION_NATIVE(func)) {
@@ -1271,7 +1267,6 @@ static bool execFnCall(Toy_Interpreter* interpreter, bool looseFirstArgument) {
Toy_freeLiteralArray(&arguments); Toy_freeLiteralArray(&arguments);
Toy_freeLiteral(func); Toy_freeLiteral(func);
Toy_freeLiteral(stackSize); Toy_freeLiteral(stackSize);
Toy_freeLiteral(identifier);
return ret; return ret;
} }

View File

@@ -0,0 +1,30 @@
{
fn a() {
fn b() {
return 42;
}
return b;
}
assert a()() == 42, "function within function failed";
}
{
fn a() {
fn b() {
fn c() {
return 42;
}
return c;
}
return b;
}
assert a()()() == 42, "function within function within function failed";
}
print "All good";

View File

@@ -117,6 +117,7 @@ int main() {
"dot-chaining.toy", "dot-chaining.toy",
"dot-modulo-bugfix.toy", "dot-modulo-bugfix.toy",
"dottify-bugfix.toy", "dottify-bugfix.toy",
"function-within-function-bugfix.toy",
"functions.toy", "functions.toy",
"index-arrays.toy", "index-arrays.toy",
"index-assignment-both-bugfix.toy", "index-assignment-both-bugfix.toy",