Skip to content

Commit

Permalink
Report error for insufficient args
Browse files Browse the repository at this point in the history
  • Loading branch information
goodpaul6 committed Dec 9, 2024
1 parent 3c8bba6 commit 84488db
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/src/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,20 @@ static void test_LeftAndRightShift() {
Tiny_DeleteState(state);
}

static void test_InsufficientArgsError() {
Tiny_State *state = CreateState();

const char *code =
"func add(x: int, y: int): int { return x + y }\n"
"a := add(10)\n";

Tiny_CompileResult result = Tiny_CompileString(state, "(insufficient args)", code);

lequal_return(result.type, TINY_COMPILE_ERROR);

Tiny_DeleteState(state);
}

int main(int argc, char *argv[]) {
lrun("Pos to friendly pos", test_PosToFriendlyPos);
lrun("All Array tests", test_Array);
Expand Down Expand Up @@ -1186,6 +1200,7 @@ int main(int argc, char *argv[]) {
lrun("Tiny Index Syntax Works", test_IndexSyntax);
lrun("Tiny Nested Struct Assignment Works", test_NestedStructAssignValue);
lrun("Tiny Left and Right Shift Works", test_LeftAndRightShift);
lrun("Tiny Insufficient Args", test_InsufficientArgsError);

lrun("Check no leak in tests", test_CheckMallocs);

Expand Down
5 changes: 5 additions & 0 deletions tiny/src/tiny.c
Original file line number Diff line number Diff line change
Expand Up @@ -2580,6 +2580,11 @@ static void ResolveTypes(Tiny_State *state, Tiny_Expr *exp) {
}
}

if (i < argc) {
ReportErrorE(state, exp, "'%s' expects (at least) %d args but you supplied %d",
exp->call.calleeName->value, argc, i);
}

exp->tag = func->type == TINY_SYM_FOREIGN_FUNCTION ? func->foreignFunc.returnTag
: func->func.returnTag;
} break;
Expand Down

0 comments on commit 84488db

Please sign in to comment.