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


bughit (bug hit) wrote:
> ```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

should also underscore that the bound method proc has access to local_var: `method_proc.()`
but its binding does not `eval('local_var', method_proc.binding)`, so there's a clear discrepancy between a proc and its binding 

----------------------------------------
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#change-65966

* 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>