Skip to content

Error @yield macro outside a @resumable function! when using @yield inside a macro #55

Description

@wmanning-cra

I wanted a macro that takes a sub-generator and yields its elements. I wrote this:

macro yieldmany(resumable::Expr)
      return quote
          for x in $(esc(resumable))
            @yield x
          end
      end
    end

However, when I use it in a function, I get an error:

@resumable function F2()
        @yield 2
        @yieldmany F1()
        @yield 4
     end
  ERROR: LoadError: LoadError: @yield macro outside a @resumable function!

I tried using macroexpand to see what it's making, but I get the same error:

@macroexpand @yieldmany F1()
ERROR: LoadError: @yield macro outside a @resumable function!
@macroexpand @yield x
ERROR: LoadError: @yield macro outside a @resumable function!

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