https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112019-11-11T13:40:18ZRuby Issue Tracking SystemRuby master - Bug #16340: There are cases where `eval("_ 1")` does not refer to Numbered parameterhttps://bugs.ruby-lang.org/issues/16340?journal_id=826082019-11-11T13:40:18ZEregon (Benoit Daloze)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>I think the behavior is expected.<br>
<code>_1</code> is a local variable in your example and eval can access local variables outside of it.</p>
<p>However, I don't think <code>_1</code> can work as numbered parameter inside an eval for a block outside the eval, because then we'd change the block arity dynamically.<br>
What would be the Proc#arity of <code>lambda { _1 + eval("_#{rand(5)}") }.arity</code> ?</p>
<p>IMHO, <code>_1</code> shouldn't be supported inside <code>eval</code> as a numbered parameter when it refers to something outside <code>eval</code>.<br>
So I think the current behavior is fine, and needs to be kept for compatibility if <code>_<n></code> is used as a local variable.</p>
<p>Do you have any realistic use case where you would want your expected behavior?</p>
<p>I mark this as rejected because I believe it's unsolvable.</p> Ruby master - Bug #16340: There are cases where `eval("_ 1")` does not refer to Numbered parameterhttps://bugs.ruby-lang.org/issues/16340?journal_id=826772019-11-13T15:31:42Zosyo (manga osyo)
<ul></ul><p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/772">@Eregon (Benoit Daloze)</a></p>
<p>Thanks comment!</p>
<blockquote>
<p>Do you have any realistic use case where you would want your expected behavior?</p>
</blockquote>
<p>No.<br>
However, I thought it was strange behavior and reported.<br>
I agree to reject.</p>