#522 new
manveru

Local variables in blocks leak their existence

Reported by manveru | May 5th, 2008 @ 11:20 AM | in 1.0 preview

I found that there is a different behaviour in rubinius for local variables assigned in a block.

# Ruby 1.8:
10.times{ bar = 1 }; bar
#=> NameError: undefined local variable or method `bar' for main:Object

# Rubinius
10.times{ bar = 1 }; bar
# nil

According to evan, the following sexp has to change.

pp "10.times { bar = 1 }; bar".to_sexp
[:block,
 [:newline,
  1,
  "(eval)",
  [:iter,
   [:call, [:lit, 10], :times],
   nil,
   [:block,
    [:dasgn_curr, :bar],
    [:newline, 1, "(eval)", [:lasgn, :bar, [:lit, 1]]]]]],
 [:newline, 1, "(eval)", [:lvar, :bar, 0]]]

that should read

pp "10.times { bar = 1 }; bar".to_sexp
[:block,
 [:newline,
  1,
  "(eval)",
  [:iter,
   [:call, [:lit, 10], :times],
   nil,
   [:block,
    [:dasgn_curr, :bar],
    [:newline, 1, "(eval)", [:lasgn, :bar, [:lit, 1]]]]]],
 [:newline, 1, "(eval)", [:vcall, :bar, 0]]]

so the :lvar on the last line becomes :vcall

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket