Skip to content

Commit

Permalink
Ban enums as variadic arguments (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli authored Jan 15, 2025
1 parent 5f42184 commit 33e7283
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/typecheck/step3_function_and_method_bodies.jou
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,13 @@ def typecheck_function_or_method_call(ft: FileTypes*, call: AstCall*, self_type:
do_implicit_cast(ft->current_fom_types, &call->args[i], intType, Location{}, NULL)
elif t == floatType:
do_implicit_cast(ft->current_fom_types, &call->args[i], doubleType, Location{}, NULL)
elif t->kind == TypeKind.Enum:
snprintf(
msg, sizeof(msg),
"enums cannot be passed to functions that take variadic arguments, such as %s",
sig->name,
)
fail(call->args[i].location, msg)

free(sigstr)
return sig->returntype
Expand Down Expand Up @@ -1017,7 +1024,7 @@ def typecheck_expression(ft: FileTypes*, expr: AstExpression*) -> None:
do_explicit_cast(ft->current_fom_types, &expr->as_->value, result, expr->location)

case _:
printf("%d\n", expr->kind)
printf("%d\n", expr->kind as int)
assert False

assert result != NULL
Expand Down
9 changes: 9 additions & 0 deletions tests/wrong_type/enum_as_vararg.jou
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "stdlib/io.jou"

enum Foo:
Bar
Baz

def main() -> int:
printf("%d\n", Foo.Bar) # Error: enums cannot be passed to functions that take variadic arguments, such as printf
return 0

0 comments on commit 33e7283

Please sign in to comment.