Repository: CQCL/guppylang

Issue:
`nat.__mod__` is broken
Currently the signature declares an `int` return and the specified `n_vars=2` also seems wrong

Discussion:

Fix (patch):
diff --git a/guppylang/src/guppylang/std/num.py b/guppylang/src/guppylang/std/num.py
index ee59519..f8561e8 100644
--- a/guppylang/src/guppylang/std/num.py
+++ b/guppylang/src/guppylang/std/num.py
@@ -83,8 +83,8 @@ class nat:
     @custom_function(BoolOpCompiler(int_op("ilt_u")))
     def __lt__(self: nat, other: nat) -> bool: ...
 
-    @hugr_op(int_op("imod_u", n_vars=2))
-    def __mod__(self: nat, other: nat) -> int: ...
+    @hugr_op(int_op("imod_u"))
+    def __mod__(self: nat, other: nat) -> nat: ...
 
     @hugr_op(int_op("imul"))
     def __mul__(self: nat, other: nat) -> nat: ...


Test changes:
diff --git a/tests/integration/test_arithmetic.py b/tests/integration/test_arithmetic.py
index 4fb32c9..e3ed731 100644
--- a/tests/integration/test_arithmetic.py
+++ b/tests/integration/test_arithmetic.py
@@ -77,7 +77,7 @@ def test_nat(validate):
     ) -> tuple[nat, bool, int, float, float]:
         b, c, d, e = nat(b), nat(c), nat(d), nat(e)
         x = a + b * c // d - e
-        y = e / b
+        y = e / b % a
         return x, bool(x), int(x), float(x), y
 
     validate(foo)
diff --git a/tests/integration/tracing/test_arithmetic.py b/tests/integration/tracing/test_arithmetic.py
index 8e4681f..7a50088 100644
--- a/tests/integration/tracing/test_arithmetic.py
+++ b/tests/integration/tracing/test_arithmetic.py
@@ -82,8 +82,7 @@ def test_nat(run_nat_fn):
     run_nat_fn(sub, 9, args=[3, 4])
     run_nat_fn(mul, 24, args=[3, 4])
     run_nat_fn(div, 20, args=[25, 10])
-    # TODO: mod is broken: https://github.com/CQCL/guppylang/issues/1257
-    # run_nat_fn(mod, 7, args=[8, 9])
+    run_nat_fn(mod, 7, args=[8, 9])
     run_nat_fn(pow, 16, args=[2, 100])