Backport #1322

define_method scope bug

Added by coderrr (coderrr .) about 3 years ago. Updated about 1 year ago.

[ruby-core:23050]
Status:Assigned Start date:03/29/2009
Priority:High Due date:
Assignee:wyhaines (Kirk Haines) % Done:

0%

Category:-
Target version:-

Description

a = 1  
 Object.send :define_method, :x do  
   lambda do
     p a
     a = 2  
     p a
   end.call  
 end  
 x(nil)
 p a

output is 1,2,1 instead of 1,2,2

details and possible fix:  http://coderrr.wordpress.com/2009/03/29/ruby-18-define_method-scope-bug/

Associated revisions

Revision 23257
Added by nobu about 3 years ago

* eval.c (proc_invoke): shares dmethod scope local variables. a patch from coderrr at [ruby-core:23050] * gc.c (obj_free): do not free cloned scope local variables.

History

Updated by coderrr (coderrr .) about 3 years ago

Any reason there have been no responses to this?

Updated by shyouhei (Shyouhei Urabe) about 3 years ago

  • Assignee set to matz (Yukihiro Matsumoto)
No, just beacuse no wan had time to look into your patch.  Sorry.  The situation is confirmed on my machine.

Updated by nobu (Nobuyoshi Nakada) about 3 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100
Applied in changeset r23257.

Updated by shyouhei (Shyouhei Urabe) about 3 years ago

  • Status changed from Closed to Open
  • Assignee changed from matz (Yukihiro Matsumoto) to shyouhei (Shyouhei Urabe)

Updated by shyouhei (Shyouhei Urabe) almost 3 years ago

  • Assignee changed from shyouhei (Shyouhei Urabe) to wyhaines (Kirk Haines)
  • Priority changed from Normal to High

Updated by wyhaines (Kirk Haines) over 2 years ago

  • Status changed from Open to Assigned
  • % Done changed from 100 to 0

Also available in: Atom PDF