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 comparing enums of different types #627

Merged
merged 2 commits into from
Jan 16, 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
1 change: 0 additions & 1 deletion compiler/constants.jou
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class Constant:
case ConstantKind.String:
printf("string ")
print_string(self->str, strlen(self->str))
printf("\n")

def free(self) -> None:
if self->kind == ConstantKind.String:
Expand Down
2 changes: 1 addition & 1 deletion compiler/typecheck/step3_function_and_method_bodies.jou
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def check_binop(
got_bools = lhs->types.type == boolType and rhs->types.type == boolType
got_integers = lhs->types.type->is_integer_type() and rhs->types.type->is_integer_type()
got_numbers = lhs->types.type->is_number_type() and rhs->types.type->is_number_type()
got_enums = lhs->types.type->kind == TypeKind.Enum and rhs->types.type->kind == TypeKind.Enum
got_enums = lhs->types.type->kind == TypeKind.Enum and lhs->types.type == rhs->types.type
got_pointers = (
lhs->types.type->is_pointer_type()
and rhs->types.type->is_pointer_type()
Expand Down
13 changes: 13 additions & 0 deletions tests/wrong_type/enums_mix_eq.jou
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
enum Foo:
Bar
Baz

enum Color:
Red
Green
Bool

def main() -> int:
if Foo.Baz == Color.Green: # Error: wrong types: cannot compare Foo and Color
pass
return 0
Loading