RFC: Some Ideas to Tackle #15276 - performance of captured variables in closures

It’s definitely a bug, and it doesn’t require @goto.

julia> function baz2()
           j = 0
           local f, i
           while j < 3
               i = j + 1
               println("i is now ", i)
               if !(j > 0)
                   f = () -> i
               end
               j += 1.0
           end
           f, nothing
       end;

julia> baz2()[1]()
i is now 1
i is now 2.0
i is now 3.0
1
julia> function baz3()
           j = 0
           local f, i
           while j < 3
               i = j + 1
               println("i is now ", i)
               if !(j > 0)
                   f = () -> i
               end
               j += 1.0
           end
           f, i
       end;

julia> baz3()[1]()
i is now 1
i is now 2.0
i is now 3.0
3.0

Would you mind filing a bug report?

3 Likes