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

feat: Add equality test for booleans #394

Merged
merged 3 commits into from
Aug 21, 2024
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
3 changes: 3 additions & 0 deletions guppylang/prelude/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def __and__(self: bool, other: bool) -> bool: ...
@guppy.custom(builtins, NoopCompiler())
def __bool__(self: bool) -> bool: ...

@guppy.hugr_op(builtins, logic_op("Eq", [tys.TypeArg(tys.BoundedNatArg(n=2))]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't n=1?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument here is to the template for boolean ops, the 2 is specifying how many inputs the function has, rather than the bound of the input Ints

def __eq__(self: bool, other: bool) -> bool: ...

@guppy.hugr_op(builtins, int_op("ifrombool"))
def __int__(self: bool) -> int: ...

Expand Down
10 changes: 10 additions & 0 deletions tests/integration/test_if.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,13 @@ def foo(x: int) -> int:
return z

validate(foo)


def test_eq(validate):
@compile_guppy
def foo() -> bool:
x = True
y = not x
return x == y

validate(foo)
Loading