Skip to content
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/std/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from __future__ import annotations

import builtins
from types import GeneratorType
from typing import TYPE_CHECKING, Generic, TypeVar, no_type_check

from guppylang.decorator import guppy
Expand Down Expand Up @@ -71,6 +72,8 @@ def copy(self: array[T, n]) -> array[T, n]: ...
def __new__(cls, *args: _T) -> builtins.list[_T]: # type: ignore[no-redef]
# Runtime array constructor that is used for comptime. We return an actual list
# in line with the comptime unpacking logic that turns arrays into lists.
if len(args) == 1 and isinstance(args[0], GeneratorType):
return list(args[0])
return [*args]


Expand Down
9 changes: 9 additions & 0 deletions tests/integration/tracing/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,12 @@ def main() -> int:
validate(compiled)
run_int_fn(compiled, 100)


def test_comprehension(validate):
@guppy.comptime
def main() -> array[int, 5]:
xs = array(i for i in range(5))
assert xs == [0, 1, 2, 3, 4]
return xs

validate(guppy.compile(main))
Loading