JuliaDynamics / ResumableFunctions.jl

C# style generators a.k.a. semi-coroutines for Julia.
Other
158 stars 19 forks source link

Fix "for" when the iterator is obtained through a function call #25

Closed Phlogistique closed 6 years ago

Phlogistique commented 6 years ago

This fixes the following issue:

julia> @resumable function foo(x)
       for i = 1:x
       @yield i
       end
       end
foo (generic function with 1 method)

julia> @resumable function bar(x)
       for i = foo(x)
       @show i; @yield i
       end
       end
bar (generic function with 1 method)

julia> i = bar(3)
getfield(Main, Symbol("##411"))(0x00, #undef, 0x30, #undef, #undef, 3)

julia> i()
_fsmi.i = 1
1

julia> i()
ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] getproperty at ./sysimg.jl:18 [inlined]
 [2] macro expansion at /home/no/.julia/packages/ResumableFunctions/wZ8aL/src/transforms.jl:14 [inlined]
 [3] (::getfield(Main, Symbol("##409")))(::Nothing) at /home/no/.julia/packages/MacroTools/4AjBS/src/utils.jl:11
 [4] iterate at /home/no/.julia/packages/MacroTools/4AjBS/src/utils.jl:84 [inlined]
 [5] macro expansion at /home/no/.julia/packages/ResumableFunctions/wZ8aL/src/transforms.jl:88 [inlined]
 [6] (::getfield(Main, Symbol("##411")))(::Nothing) at /home/no/.julia/packages/MacroTools/4AjBS/src/utils.jl:11
 [7] (::getfield(Main, Symbol("##411")))() at /home/no/.julia/packages/MacroTools/4AjBS/src/utils.jl:84
 [8] top-level scope at none:0
coveralls commented 6 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling b4d45509674add034628cd2e5c6748275b8e65c1 on Phlogistique:fix_for into d7755772d14d324293d62e66094c1e1dcad9a8ac on BenLauwens:master.

Phlogistique commented 6 years ago

The AppVeyor build fail seems to be unrelated.