Skip to content

parametric vararg resumable function throws when called with no arguments #170

Description

@singhharsh1708

A parametric vararg resumable function throws when it's called with no arguments.

using ResumableFunctions

@resumable function res(a::T...) where T
    @yield length(a)
end

collect(res(1, 2))  # Any[2]
collect(res())      # UndefVarError: `T` not defined in static parameter matching

The plain function returns 0 there. The wrapper constructs the state machine as ##res_FSMI#...{T}, and an empty vararg leaves T unbound.

Recursion that peels arguments off hits it on the last step:

@resumable function peel(a::T...) where T
    if !isempty(a)
        @yield first(a)
        @yieldfrom peel(Base.tail(a)...)
    end
end

collect(peel(1, 2, 3))  # same UndefVarError

v1.0.7, same on julia 1.10.10, 1.11.9 and 1.12.7. On 1.10 the message is just UndefVarError: T not defined.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions