https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112016-11-28T03:27:11ZRuby Issue Tracking SystemRuby master - Bug #12984: `rescue *[]` should be equivalent to `rescue` as `method_call(*[])` is equivalent to `method_call`https://redmine.ruby-lang.org/issues/12984?journal_id=617692016-11-28T03:27:11Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>It's similar to:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">super</span><span class="p">(</span><span class="o">*</span><span class="p">[])</span>
</code></pre> Ruby master - Bug #12984: `rescue *[]` should be equivalent to `rescue` as `method_call(*[])` is equivalent to `method_call`https://redmine.ruby-lang.org/issues/12984?journal_id=617762016-11-28T16:27:52Zbughit (bug hit)
<ul></ul><p>Nobuyoshi Nakada wrote:</p>
<blockquote>
<p>It's similar to:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">super</span><span class="p">(</span><span class="o">*</span><span class="p">[])</span>
</code></pre>
</blockquote>
<p>I guess there's some similarity. But super has a very explicit definition. Only a naked super is auto-forwarding, any attempt to pass args turns it into manual super. So <code>super(*[])</code> is equivalent to <code>super()</code>, which makes sense, because by doing <code>super(*array)</code> you are clearly trying to call explicit super.</p> Ruby master - Bug #12984: `rescue *[]` should be equivalent to `rescue` as `method_call(*[])` is equivalent to `method_call`https://redmine.ruby-lang.org/issues/12984?journal_id=617772016-11-28T17:31:05Zbughit (bug hit)
<ul></ul><p>bug hit wrote:</p>
<blockquote>
<p>Nobuyoshi Nakada wrote:</p>
<blockquote>
<p>It's similar to:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">super</span><span class="p">(</span><span class="o">*</span><span class="p">[])</span>
</code></pre>
</blockquote>
<p>I guess there's some similarity. But super has a very explicit definition. Only a naked super is auto-forwarding, any attempt to pass args turns it into manual super. So <code>super(*[])</code> is equivalent to <code>super()</code>, which makes sense, because by doing <code>super(*array)</code> you are clearly trying to call explicit super.</p>
</blockquote>
<p>The difference between rescue and super is that there is such a thing as an explicit empty <code>super()</code> that passes nothing, but there is no corresponding explicit empty <code>rescue()</code> that rescues nothing, and so rescue *[] manifests something that isn't supposed to exist.</p> Ruby master - Bug #12984: `rescue *[]` should be equivalent to `rescue` as `method_call(*[])` is equivalent to `method_call`https://redmine.ruby-lang.org/issues/12984?journal_id=800372019-07-25T18:29:55Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>This is the expected behavior. <code>rescue *array</code> should mean rescue only exception classes in the array. It should not mean rescue only exception classes in the array, unless the array is empty, in which case rescue StandardError. Otherwise you end up changing the meaning of things like:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">exceptions</span><span class="o">=</span><span class="p">[]</span>
<span class="n">exceptions</span> <span class="o"><<</span> <span class="no">ArgumentError</span> <span class="k">if</span> <span class="no">ENV</span><span class="p">[</span><span class="s2">"ArgumentError"</span><span class="p">]</span>
<span class="k">begin</span>
<span class="k">raise</span> <span class="no">ArgumentError</span><span class="p">,</span> <span class="s2">"x"</span>
<span class="k">rescue</span> <span class="o">*</span><span class="n">exceptions</span>
<span class="nb">puts</span> <span class="s2">"caught"</span>
<span class="k">end</span>
</code></pre> Ruby master - Bug #12984: `rescue *[]` should be equivalent to `rescue` as `method_call(*[])` is equivalent to `method_call`https://redmine.ruby-lang.org/issues/12984?journal_id=814042019-09-05T22:29:17Zbughit (bug hit)
<ul><li><strong>Status</strong> changed from <i>Closed</i> to <i>Feedback</i></li></ul><p>I stopped getting email notifications from bugs.ruby-lang.org, to whom should I report this?</p>
<p>I am going to reopen this because I did not have a chance to address your comment. And I made an argument that so far has not been addressed.</p>
<blockquote>
<p>It should not mean rescue only exception classes in the array, unless the array is empty</p>
</blockquote>
<p>That's not consistent with the meaning of splatting an empty array, whereas the opposite is.</p>
<p>In a construct that takes a coma separated list, splatting an empty array produces a void list (no values)</p>
<p>so <code>rescue *[Class1, Class2]</code> translates to <code>rescue Class1, Class2</code><br>
<code>rescue *[Class1]</code> translates to <code>rescue Class1</code><br>
and <code>rescue *[]</code> to a plain <code>rescue</code> which does not mean rescue nothing</p>
<p>That would be logical and consistent.</p>
<p>There is no explicit syntax for rescue nothing which would be something like <code>rescue()</code>, so <code>rescue *[]</code> has to mean <code>rescue</code> and not the non-existent <code>rescue()</code></p> Ruby master - Bug #12984: `rescue *[]` should be equivalent to `rescue` as `method_call(*[])` is equivalent to `method_call`https://redmine.ruby-lang.org/issues/12984?journal_id=814062019-09-05T22:44:51Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li></ul><p>bughit (bug hit) wrote:</p>
<blockquote>
<p>I stopped getting email notifications from bugs.ruby-lang.org, to whom should I report this?</p>
</blockquote>
<p>I'm not sure.</p>
<blockquote>
<p>I am going to reopen this because I did not have a chance to address your comment. And I made an argument that so far has not been addressed.</p>
</blockquote>
<p>Your argument is basically that <code>rescue *[]</code> should mean <code>rescue</code>. In reality, <code>rescue</code> is a shortcut for <code>rescue *[StandardError]</code>. If you look at it from that perspective, it is obvious that <code>rescue *[]</code> and <code>rescue *[StandardError]</code> should not be the same thing.</p>
<blockquote>
<blockquote>
<p>It should not mean rescue only exception classes in the array, unless the array is empty</p>
</blockquote>
<p>That's not consistent with the meaning of splatting an empty array, whereas the opposite is.</p>
<p>In a construct that takes a coma separated list, splatting an empty array produces a void list (no values)</p>
<p>so <code>rescue *[Class1, Class2]</code> translates to <code>rescue Class1, Class2</code><br>
<code>rescue *[Class1]</code> translates to <code>rescue Class1</code><br>
and <code>rescue *[]</code> to a plain <code>rescue</code> which does not mean rescue nothing</p>
<p>That would be logical and consistent.</p>
<p>There is no explicit syntax for rescue nothing which would be something like <code>rescue()</code>, so <code>rescue *[]</code> has to mean <code>rescue</code> and not the non-existent <code>rescue()</code></p>
</blockquote>
<p>The explicit syntax for rescue nothing is <code>rescue *[]</code> :) . As I showed in my earlier example, changing <code>rescue *array</code> to mean <code>rescue StandardError</code> if the array is empty will break backwards compatibility.</p>
<p>Assigning to matz to make a decision on this.</p> Ruby master - Bug #12984: `rescue *[]` should be equivalent to `rescue` as `method_call(*[])` is equivalent to `method_call`https://redmine.ruby-lang.org/issues/12984?journal_id=814122019-09-06T03:59:03Zsawa (Tsuyoshi Sawada)
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/81412/diff?detail_id=55033">diff</a>)</li></ul> Ruby master - Bug #12984: `rescue *[]` should be equivalent to `rescue` as `method_call(*[])` is equivalent to `method_call`https://redmine.ruby-lang.org/issues/12984?journal_id=814292019-09-06T17:37:05Zbughit (bug hit)
<ul></ul><blockquote>
<p>The explicit syntax for rescue nothing is rescue *[] :)</p>
</blockquote>
<p>Splat is not part of the rescue syntax, it composes with it, the same way it composes with other constructs that take a comma separated list (invocations, not sure if there are others).</p>
<p>Here's an excerpt from "The ruby programming language"</p>
<hr>
<p>Here’s how we would write a rescue clause to handle exceptions of either<br>
of these types and assign the exception object to the variable error:</p>
<p>rescue ArgumentError, TypeError => error</p>
<p>Here, finally, we see the syntax of the rescue clause at its most general. The rescue<br>
keyword is followed by zero or more comma-separated expressions, each of which must<br>
evaluate to a class object that represents the Expression class or a subclass. These<br>
expressions are optionally followed by => and a variable name.</p>
<hr>
<p>It documents the specific synax of rescue but does not even mention the splat, which does not have any special meaning in this context and its general meaning is <code>*[] == a void list</code>, so <code>rescue *[] == rescue</code></p> Ruby master - Bug #12984: `rescue *[]` should be equivalent to `rescue` as `method_call(*[])` is equivalent to `method_call`https://redmine.ruby-lang.org/issues/12984?journal_id=814422019-09-07T10:06:33ZEregon (Benoit Daloze)
<ul></ul><p>The core of this is that <code>rescue</code> (which means rescue StandardError) vs <code>rescue *classes</code> (which means rescue any of <code>classes</code>) is detected at parse time, not at runtime.<br>
I think the current logic makes sense in that regard, and I think it's is less surprising than <code>rescue *no_classes</code> to "magically" rescue <code>StandardError</code>.</p> Ruby master - Bug #12984: `rescue *[]` should be equivalent to `rescue` as `method_call(*[])` is equivalent to `method_call`https://redmine.ruby-lang.org/issues/12984?journal_id=814852019-09-09T17:16:04Zbughit (bug hit)
<ul></ul><blockquote>
<p>I think it's is less surprising than rescue *no_classes to "magically" rescue StandardError</p>
</blockquote>
<p>It is the current behavior that's magical. If you try to deduce what <code>rescue *[]</code> means from the primitives, it goes like this:</p>
<ul>
<li>
<code>*[]</code> means a void (non-existent) list</li>
<li>therefore <code>rescue *[]</code> means <code>rescue</code>. It can't mean <code>rescue()</code> (like <code>super()</code>) because <code>rescue()</code> does not exist</li>
</ul>
<p>Anything but the above is special-casing, i.e. magic</p> Ruby master - Bug #12984: `rescue *[]` should be equivalent to `rescue` as `method_call(*[])` is equivalent to `method_call`https://redmine.ruby-lang.org/issues/12984?journal_id=815872019-09-19T05:26:23Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul><p>This <code>*[]</code> is not just exception list omitted, but explicitly specifies zero exceptions to catch.<br>
Thus the current behavior is intended.</p>
<p>Matz.</p>