JuliaDynamics / ResumableFunctions.jl

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

LoadError when yielding tuple with field name identical to local variable name #32

Open marc-hofmann opened 5 years ago

marc-hofmann commented 5 years ago

The following

@resumable function my_generator()
    x = 0
    @yield (x = 1, )
end

fails with

ERROR: LoadError: syntax: invalid named tuple field name "_fsmi.x"

No error is raised if the field name is changed:

@resumable function my_generator()
    x = 0
    @yield (y = 1, )
end

Julia 1.0.2, ResumableFunctions 0.4.2

BenLauwens commented 5 years ago

Hi

Error is logical. The symbol x is the name of a slot in the method and all symbols x are replaced by _fsmi.x to transform the function in a state machine. I will try to bypass this general rule for named tuples. I keep you informed of progress!

Kind regards

Ben

marc-hofmann commented 5 years ago

Hi, Ben

Thank you for the explanation.

Best, Marc