Ruby Issue Tracking System: Issueshttps://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112019-01-14T19:52:03ZRuby Issue Tracking System
Redmine Ruby master - Bug #15535 (Rejected): Optional arguments for definition - Syntax Error is not the ...https://redmine.ruby-lang.org/issues/155352019-01-14T19:52:03Zwaheedi (Waheed Barghouthi)waheed.barghouthi@gmail.com
<p>The below definition throws a Syntax Error, while there is no syntax error and I'm not sure what is the intention behind the Syntax Error</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">def</span> <span class="nf">hello</span><span class="p">(</span><span class="n">foo</span><span class="o">=</span><span class="s2">"bar"</span><span class="p">,</span> <span class="n">bar</span><span class="p">,</span> <span class="n">yanko</span><span class="o">=</span><span class="s2">"me"</span><span class="p">)</span>
<span class="nb">p</span> <span class="s2">"Hello"</span>
<span class="k">end</span>
</code></pre>
<p>The same definition below with a tiny modification in the argument set, give a Syntax OK.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">def</span> <span class="nf">hello</span><span class="p">(</span><span class="n">foo</span><span class="o">=</span><span class="s2">"bar"</span><span class="p">,</span> <span class="n">bar</span><span class="o">=</span><span class="s2">"foo"</span><span class="p">,</span> <span class="n">yanko</span><span class="o">=</span><span class="s2">"me"</span><span class="p">)</span>
<span class="nb">p</span> <span class="s2">"Hello"</span>
<span class="k">end</span>
</code></pre>
<p>It seems when there is a required argument in the definition that happens to be in between optional arguments that triggers a Syntax Error, I think the ArgumentError is more related to it.</p>
<p>This has been tested on mostly every ruby version after 1.8.7 and it gave the same result.</p>