Issue #13774 has been reported by bughit (bug hit).

----------------------------------------
Bug #13774: for methods defined from procs, the binding of the resulting bound method proc does not have access to the original proc's closure environment
https://bugs.ruby-lang.org/issues/13774

* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
```ruby
def foo
  o = Object.new
  local_var = 'local_var'
  method_lambda = ->{local_var}
  o.define_singleton_method(:lambda_method, &method_lambda)
  method_proc = o.method(:lambda_method).to_proc
  puts method_proc.()
  puts eval('local_var', method_lambda.binding)
  puts o.lambda_method
  puts eval('local_var', method_proc.binding) # undefined local variable or method `local_var'
end

foo
```

when executed as a method it has access to local_var as expected
but the binding of the bound method proc does not

in ruby 2.2.2 the above code crashes the vm



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>