From dd702ce5e5e5f363b3a31e0075690703f2fe6d29 Mon Sep 17 00:00:00 2001 From: Craig Roy Date: Wed, 21 Aug 2024 09:45:19 +0100 Subject: [PATCH] feat: Add equality test for booleans (#394) Closes #363 --- guppylang/prelude/builtins.py | 3 +++ tests/integration/test_if.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/guppylang/prelude/builtins.py b/guppylang/prelude/builtins.py index a4a93f09..a11a75a1 100644 --- a/guppylang/prelude/builtins.py +++ b/guppylang/prelude/builtins.py @@ -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))])) + def __eq__(self: bool, other: bool) -> bool: ... + @guppy.hugr_op(builtins, int_op("ifrombool")) def __int__(self: bool) -> int: ... diff --git a/tests/integration/test_if.py b/tests/integration/test_if.py index 67dfb7be..4cf42906 100644 --- a/tests/integration/test_if.py +++ b/tests/integration/test_if.py @@ -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)