https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112017-09-25T18:15:34ZRuby Issue Tracking SystemRuby master - Bug #13939: Ruby 2.4.2 has issue supporting Seattle.rb style for define_methodhttps://redmine.ruby-lang.org/issues/13939?journal_id=669132017-09-25T18:15:34Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>Let's ignore the "Seattle.rb style" for the moment because I don't know of such a<br>
thing - may well be seattle-duck style. :P</p>
<p>But anyway, I agree with you in at the least one point, which is the warning message:</p>
<blockquote>
<p>Anyone who tries to load my 'read_source' gem will get a failure message<br>
in require without explaining the specific area of code.</p>
</blockquote>
<p>Perhaps the error message could be more indicative of the error or what the exact<br>
problem is or how to solve it. I understand that the () provide additional information<br>
that is in some way useful to the parser, or whatever is responsible, so perhaps the<br>
message above could be changed somewhat.</p>
<p>I guess ruby core prefers short messages when possible (aka "syntax error, unexpected '}'")<br>
but this is indeed not always extremely helpful. With more recent changes such as the<br>
did-you-mean-gem, but also some other discussions about better and more fine-tuned<br>
control over warnings/error messages, that may be more helpful to the average ruby<br>
hacker.</p>
<p>To the issue about differential parsing, that is actually indeed strange.</p>
<p>Even more surprising is that I actually thought that:</p>
<pre><code>define_method(:some_method_name) { "asdf" }
</code></pre>
<p>Is the only way to use define_method() :D</p>
<p>I think I used that always ...</p>
<p>It reminds me a bit of:</p>
<pre><code>get '/' do
play_intro_music
end
</code></pre>
<p>versus</p>
<pre><code>get '/' { play_intro_music }
# which does not work
</code></pre>
<p>versus</p>
<pre><code>get('/') { play_intro_music }
</code></pre>
<p>which works. I always thought that in some cases the ruby parse<br>
needs the (). I'd love to be able to make them optional in the<br>
second case. Oddly enough, for method DEFINITIONS, I always use<br>
() when there are arguments, so "def foo(bar)" is what I prefer<br>
over "def foo bar". This is more an aside though, it is strange<br>
that this changed.</p>
<p>By the way your last example does not work as-is :D</p>
<pre><code>define_method :johny, instance_method(:apple)
</code></pre>
<p>NoMethodError: undefined method `instance_method' for main:Object</p>
<p>Sorry for nitpicking there, I understand what you mean.</p>
<p>I guess it may be because of {} having different meanings in ruby<br>
but then again, there was probably some reason unless it was an<br>
accident. It's ~3:15 in Tokyo so I guess in a few hours perhaps<br>
some from the ruby core team can chime in. I did not even know<br>
that we could omit the () there, that was awesome if that was<br>
possible. I remember in my code though, that whenever I used<br>
define_method(), I always used () ... usually in combination with<br>
some <em>eval</em> method thing.</p> Ruby master - Bug #13939: Ruby 2.4.2 has issue supporting Seattle.rb style for define_methodhttps://redmine.ruby-lang.org/issues/13939?journal_id=669162017-09-25T21:10:45Zasterite (Ary Borenszweig)asterite@gmail.com
<ul></ul><p>I think this was introduced in <a href="https://github.com/ruby/ruby/commit/9987109" class="external">https://github.com/ruby/ruby/commit/9987109</a></p>
<p>Basically, any call <code>foo arg { }</code> when <code>arg</code> is a literal now gives an error.</p>
<p>I think this is a huge breaking change, for example if you had something like:</p>
<pre><code>describe "foo" {
it "does something" {
}
}
</code></pre>
<p>Now it no longer works, though I don't know if someone writes code like that.</p>
<p>Maybe the error makes sense because <code>{</code> binds the thing to its left as a block, but I don't know :-)</p> Ruby master - Bug #13939: Ruby 2.4.2 has issue supporting Seattle.rb style for define_methodhttps://redmine.ruby-lang.org/issues/13939?journal_id=669172017-09-25T21:19:26Zdanielpclark (Daniel P. Clark)6ftdan@gmail.com
<ul></ul><blockquote>
<p>Perhaps the error message could be more indicative of the error or what the exact<br>
problem is or how to solve it. I understand that the () provide additional information<br>
that is in some way useful to the parser, or whatever is responsible, so perhaps the<br>
message above could be changed somewhat.</p>
</blockquote>
<blockquote>
<p>I guess ruby core prefers short messages when possible (aka "syntax error, unexpected '}'")<br>
but this is indeed not always extremely helpful. With more recent changes such as the<br>
did-you-mean-gem, but also some other discussions about better and more fine-tuned<br>
control over warnings/error messages, that may be more helpful to the average ruby<br>
hacker.</p>
</blockquote>
<p>I apologize I wrote that earlier with a different error message. Here's what importing 'read_source' does in Ruby 2.4.2 (but will work for any other version of Ruby).</p>
<pre><code>/usr/share/rvm/rubies/ruby-2.3.5/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- read_source (LoadError)
from /usr/share/rvm/rubies/ruby-2.3.5/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/danielpclark/dev/faster_path/test/monkeypatches/faster_path_test.rb:3:in `<top (required)>'
from /usr/share/rvm/rubies/ruby-2.3.5/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/share/rvm/rubies/ruby-2.3.5/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/danielpclark/.rvm/gems/ruby-2.3.5/gems/rake-12.0.0/lib/rake/rake_test_loader.rb:15:in `block in <main>'
from /home/danielpclark/.rvm/gems/ruby-2.3.5/gems/rake-12.0.0/lib/rake/rake_test_loader.rb:4:in `select'
from /home/danielpclark/.rvm/gems/ruby-2.3.5/gems/rake-12.0.0/lib/rake/rake_test_loader.rb:4:in `<main>'
rake aborted!
Command failed with status (1)
/home/danielpclark/.rvm/gems/ruby-2.3.5/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/home/danielpclark/.rvm/gems/ruby-2.3.5/bin/ruby_executable_hooks:15:in `eval'
/home/danielpclark/.rvm/gems/ruby-2.3.5/bin/ruby_executable_hooks:15:in `<main>'
</code></pre>
<p>I wasn't going to include it here because I think that problem should be a different bug report. The same error will occur for gem 'method_source' and only for Ruby 2.4.2. I'm not sure this require issue is a Ruby bug yet. It looks like it could be RVM not using the right gem set with Ruby 2.4.2.</p>
<p>The error shown in this bug report is not from being required but from running the test suite in the gem.</p>
<blockquote>
<p>By the way your last example does not work as-is :D</p>
</blockquote>
<p>Ah, for that last example there should be a method defined within a class.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">class</span> <span class="nc">Example</span>
<span class="k">def</span> <span class="nf">apple</span>
<span class="s2">"Johny Apple Seed was here"</span>
<span class="k">end</span>
<span class="n">define_method</span> <span class="ss">:johny</span><span class="p">,</span> <span class="nb">instance_method</span><span class="p">(</span><span class="ss">:apple</span><span class="p">)</span>
<span class="k">end</span>
</code></pre> Ruby master - Bug #13939: Ruby 2.4.2 has issue supporting Seattle.rb style for define_methodhttps://redmine.ruby-lang.org/issues/13939?journal_id=669182017-09-25T21:30:03Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Is duplicate of</strong> <i><a class="issue tracker-1 status-6 priority-4 priority-default closed" href="/issues/13898">Bug #13898</a>: Block parsing regression</i> added</li></ul> Ruby master - Bug #13939: Ruby 2.4.2 has issue supporting Seattle.rb style for define_methodhttps://redmine.ruby-lang.org/issues/13939?journal_id=669202017-09-25T21:39:57Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>It's a bug in 2.4.0 and 2.4.1 only.<br>
Braces just after a literal has caused a syntax error before, like as:</p>
<p>danielpclark (Daniel P. Clark) wrote:</p>
<blockquote>
<p>I apologize I wrote that earlier with a different error message. Here's what importing 'read_source' does in Ruby 2.4.2 (but will work for any other version of Ruby).</p>
<pre><code>/usr/share/rvm/rubies/ruby-2.3.5/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- read_source (LoadError)
</code></pre>
</blockquote>
<p>A brace block has higher precedence and is bound to the previous expression, and a literal cannot be a method call and have a block.</p>
<p>shevegen (Robert A. Heiler) wrote:</p>
<blockquote>
<p>I guess ruby core prefers short messages when possible (aka "syntax error, unexpected '}'")<br>
but this is indeed not always extremely helpful.</p>
</blockquote>
<p>Unfortunately, this message is generated by bison, not us.</p> Ruby master - Bug #13939: Ruby 2.4.2 has issue supporting Seattle.rb style for define_methodhttps://redmine.ruby-lang.org/issues/13939?journal_id=670652017-10-05T08:01:15Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Has duplicate</strong> <i><a class="issue tracker-1 status-5 priority-4 priority-default closed" href="/issues/13976">Bug #13976</a>: SyntaxError if curly brace block follows args without parentheses, introduced in 2.4.2</i> added</li></ul> Ruby master - Bug #13939: Ruby 2.4.2 has issue supporting Seattle.rb style for define_methodhttps://redmine.ruby-lang.org/issues/13939?journal_id=677622017-11-10T08:01:38Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li><li><strong>Assignee</strong> set to <i>nobu (Nobuyoshi Nakada)</i></li></ul>