From: "jeremyevans0 (Jeremy Evans)" Date: 2022-01-06T00:02:48+00:00 Subject: [ruby-core:106978] [Ruby master Feature#18461] closures are capturing unused variables Issue #18461 has been updated by jeremyevans0 (Jeremy Evans). This is Ruby, you can always modify the value of the local variable later, even if it isn't accessed inside the proc itself. Such access can affect other scopes: ```ruby def foo a = 1 [->{}, ->{}] end x, y = foo x.binding.local_variable_get(:a) # => 1 y.binding.local_variable_get(:a) # => 1 x.binding.local_variable_set(:a, 2) x.binding.local_variable_get(:a) # => 2 y.binding.local_variable_get(:a) # => 2 ``` I would guess that changing this to optimize away the local variable in the proc's binding would break code. ---------------------------------------- Feature #18461: closures are capturing unused variables https://bugs.ruby-lang.org/issues/18461#change-95808 * Author: bughit (bug hit) * Status: Open * Priority: Normal ---------------------------------------- ```rb def foo a = 1 ->{} end p foo.binding.local_variables # [:a] ``` Shouldn't `a` be optimized away? Like v8 does (https://bugs.chromium.org/p/v8/issues/detail?id=3491) -- https://bugs.ruby-lang.org/ Unsubscribe: