Skip to content

Commit

Permalink
Ban enums as variadic arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Jan 15, 2025
1 parent 5f42184 commit ec736b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions 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
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 ec736b5

Please sign in to comment.