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

@resumable breaks blocks scope #69

Closed
Krastanov opened this issue Aug 8, 2023 · 2 comments
Closed

@resumable breaks blocks scope #69

Krastanov opened this issue Aug 8, 2023 · 2 comments
Labels
edge case syntax Standard syntax or scoping that breaks or gives wrong results with @resumable
Milestone

Comments

@Krastanov
Copy link
Member

Base Julia and ResumableFunctions.@resumable treat let blocks (and potentially others) differently

julia> function f()
           i = 1
           let j=i
               val = j
           end
           return val
       end
       f()
ERROR: UndefVarError: `val` not defined
Stacktrace:
 [1] f()
   @ Main ./REPL[114]:6
 [2] top-level scope
   @ REPL[114]:8

julia> @resumable function g()
           i = 1
           let j=i
               val = j
           end
           @yield val
       end
       collect(g())
1-element Vector{Any}:
 1
@Krastanov Krastanov added this to the 1.0 milestone Aug 8, 2023
@Krastanov Krastanov changed the title @resumable breaks let blocks scope @resumable breaks blocks scope Feb 25, 2024
@Krastanov
Copy link
Member Author

and of course this is not only with let:

julia> @resumable function h()
           for i in 1:10
           end
           @yield i
       end
h (generic function with 1 method)

julia> collect(h())
1-element Vector{Any}:
 10

julia> function h1()
           for i in 1:10
           end
           return i
       end
h1 (generic function with 1 method)

julia> h1()
ERROR: UndefVarError: `i` not defined
Stacktrace:
 [1] h1()
   @ Main ./REPL[134]:4
 [2] top-level scope
   @ REPL[135]:1

@Krastanov
Copy link
Member Author

discussion from slack on this topic:

image

image

image

@Krastanov Krastanov added the edge case syntax Standard syntax or scoping that breaks or gives wrong results with @resumable label May 3, 2024
@thofma thofma mentioned this issue Aug 8, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
edge case syntax Standard syntax or scoping that breaks or gives wrong results with @resumable
Projects
None yet
Development

No branches or pull requests

1 participant