Skip to content

Commit

Permalink
fix: Enable len for linear arrays (#576)
Browse files Browse the repository at this point in the history
Closes #570
  • Loading branch information
mark-koch authored Oct 18, 2024
1 parent c698b43 commit 117b68e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
2 changes: 1 addition & 1 deletion guppylang/prelude/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ def __getitem__(self: array[L, n], idx: int) -> L: ...
def __setitem__(self: array[L, n], idx: int, value: L @ owned) -> None: ...

@guppy.custom(checker=ArrayLenChecker())
def __len__(self: array[T, n]) -> int: ...
def __len__(self: array[L, n]) -> int: ...

@guppy.custom(NewArrayCompiler(), NewArrayChecker(), higher_order_value=False)
def __new__(): ...
Expand Down
7 changes: 0 additions & 7 deletions tests/error/array_errors/linear_len.err

This file was deleted.

17 changes: 0 additions & 17 deletions tests/error/array_errors/linear_len.py

This file was deleted.

18 changes: 18 additions & 0 deletions tests/integration/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ def main(xs: array[float, 42]) -> int:
assert val.val.v == 42


def test_len_linear(validate):
module = GuppyModule("test")
module.load(qubit)

@guppy(module)
def main(qs: array[qubit, 42]) -> int:
return len(qs)

package = module.compile()
validate(package)

hg = package.module
[val] = [data.op for node, data in hg.nodes() if isinstance(data.op, ops.Const)]
assert isinstance(val, ops.Const)
assert isinstance(val.val, IntVal)
assert val.val.v == 42


def test_index(validate):
@compile_guppy
def main(xs: array[int, 5], i: int) -> int:
Expand Down

0 comments on commit 117b68e

Please sign in to comment.