From: Colin Bartlett Date: 2011-01-18T04:03:41+09:00 Subject: Re: Obscure syntax error On Mon, Jan 17, 2011 at 12:39 PM, Rolf Timmermans wrote: > ... > Exactly. And to be entirely clear, the fact that the method does not exist doesn't even matter. > If the method does exist, the same syntax error is raised if the first argument is a symbol. > And when using parentheses, no syntax error occurs > ... > def x(*args); end > x :y > # No error > > def x(*args); end > x = nil > x :y > # foo.rb:3: syntax error, unexpected ':', expecting $end > > def x(*args); end > x = nil > x(:y) > # No error I don't have an explanation for why using the symbol gives a SyntaxError rather than a NoMethodError, but the above three of your new examples seem to me to be the key examples, together with maybe the following on Ruby1.9.1. Note that using "eval" with x not being defined as a variable also raises a SyntaxError. ## two types of error message: ## NoMethodErr === # ## SyntaxErr === # #{defined?( x ).inspect}" (x :y) rescue (p $!) # NoMethodErr (x 'y') rescue (p $!) # NoMethodErr (x y) rescue (p $!) # NoMethodErr puts "** eval; defined?( x ) #=> #{defined?( x ).inspect}" begin; eval "(x :y)"; rescue SyntaxError; p $!; end # SyntaxErr eval "(x 'y')" rescue (p $!) # NoMethodErr eval "(x y)" rescue (p $!) # NoMethodErr