Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ban enums as variadic arguments #628

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading