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

len of generic array causing InternalGuppyError #804

Open
ss2165 opened this issue Feb 12, 2025 · 0 comments
Open

len of generic array causing InternalGuppyError #804

ss2165 opened this issue Feb 12, 2025 · 0 comments
Assignees

Comments

@ss2165
Copy link
Member

ss2165 commented Feb 12, 2025

example:

@guppy
@no_type_check
def array_any(arr: array[bool, n]) -> bool:
    for i in range(len(arr)):
        if arr[i]:
            return True
    return False

throws


    @staticmethod
    def _get_const_len(inst: Inst) -> ast.expr:
        """Helper function to extract the static length from the inferred type args."""
        # TODO: This will stop working once we allow generic function defs. Then, the
        #  argument could also just be variable instead of a concrete number.
        match inst:
            case [_, ConstArg(const=ConstValue(value=int(n)))]:
                return ast.Constant(value=n)
>       raise InternalGuppyError(f"array.__len__: Invalid instantiation: {inst}")
E       guppylang.error.InternalGuppyError: array.__len__: Invalid instantiation: [TypeArg(ty=OpaqueType(args=[], defn=OpaqueTypeDef(id=DefId(id=3, module=None), name='bool', defined_at=None, description='type', params=[], never_copyable=False, never_droppable=False, to_hugr=<function <lambda> at 0x106ccae80>, bound=None))), ConstArg(const=BoundConstVar(ty=NumericType(kind=<Kind.Nat: 1>), display_name='n', idx=0))]

using range(n) instead works, but I believe this is a regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants