guppylang icon indicating copy to clipboard operation
guppylang copied to clipboard

`nat @ comptime` argument not recognised in nested function signature

Open GBoydQ opened this issue 6 months ago • 1 comments

When using a nat @ comptime in the signature of a nested function, the variable is not defined

@guppy
def foo(n: nat @ comptime) -> None:
    @guppy
    def bar(arr: 'array[nat, n]') -> None:
        pass

gives n is not defined

GBoydQ avatar Jun 17 '25 15:06 GBoydQ

Thanks for reporting! Currently, nested functions can't refer to parameters from the outside, but I agree this would be nice addition. Created issue #1050 to track this.

For now, you should be able to get away with defining bar outside of foo:

n = guppy.nat_var("n")

@guppy
def _bar(arr: 'array[nat, n]') -> None:
    pass

@guppy
def foo(n: nat @ comptime) -> None:
    bar = _bar[n]

mark-koch avatar Jun 24 '25 08:06 mark-koch