Bug #4561

1.9.2 requires parentheses around argument of method call in an array, where 1.8.7 did not

Added by Dave Schweisguth about 3 years ago. Updated almost 3 years ago.

[ruby-core:35637]
Status:Closed
Priority:Normal
Assignee:Koichi Sasada
Category:core
Target version:1.9.3
ruby -v:- Backport:

Description

[dave hladik:~] cat methodcallwithoutparensinarray.rb
def method
name(arg)
end

[ methodname 'value' ]
[dave hladik:~] ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10]
[dave hladik:~] ruby method
callwithoutparensinarray.rb
[dave hladik:~] rvm 1.9.2
[dave hladik:~] ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x8664-darwin10.7.0]
[dave hladik:~] ruby method
callwithoutparensinarray.rb
methodcallwithoutparensinarray.rb:4: syntax error, unexpected tSTRINGBEG, expecting keyworddo or '{' or '('
[ method
name 'value' ]
^
methodcallwithoutparensinarray.rb:4: syntax error, unexpected ']', expecting $end
[dave hladik:~] rvm system
[dave hladik:~] ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10]
[dave hladik:~] cat method
callwithparensinarray.rb
def method_name(arg)
end

[ methodname('value') ]
[dave hladik:~] ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10]
[dave hladik:~] ruby method
callwithparensinarray.rb
[dave hladik:~] rvm 1.9.2
[dave hladik:~] ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x8664-darwin10.7.0]
[dave hladik:~] ruby method
callwithparensinarray.rb

no error

method_call_without_parens_in_array.rb Magnifier (50 Bytes) Dave Schweisguth, 04/07/2011 01:41 PM

method_call_with_parens_in_array.rb Magnifier (51 Bytes) Dave Schweisguth, 04/07/2011 01:41 PM

History

#1 Updated by Dave Schweisguth about 3 years ago

=begin
Same thing with pre formatting:

[dave hladik:~] cat methodcallwithoutparensinarray.rb
def method
name(arg)
end

[ methodname 'value' ]
[dave hladik:~] rvm system
[dave hladik:~] ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10]
[dave hladik:~] ruby method
callwithoutparensinarray.rb
[dave hladik:~] rvm 1.9.2
[dave hladik:~] ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x8664-darwin10.7.0]
[dave hladik:~] ruby method
callwithoutparensinarray.rb
methodcallwithoutparensinarray.rb:4: syntax error, unexpected tSTRINGBEG, expecting keyworddo or '{' or '('
[ method
name 'value' ]
^
methodcallwithoutparensinarray.rb:4: syntax error, unexpected ']', expecting $end
[dave hladik:~] cat method
callwithparensinarray.rb
def method_name(arg)
end

[ methodname('value') ]
[dave hladik:~] rvm system
[dave hladik:~] ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10]
[dave hladik:~] ruby method
callwithparensinarray.rb
[dave hladik:~] rvm 1.9.2
[dave hladik:~] ruby methodcallwithparensin_array.rb
# no error
=end

#2 Updated by Yui NARUSE about 3 years ago

  • Status changed from Open to Assigned
  • Assignee set to Yukihiro Matsumoto

=begin

=end

#3 Updated by Benoit Daloze about 3 years ago

=begin
That has bitten me a few times too, but I accepted it as it is probably clearer in a long expression.

I'm curious to see why this changed.
=end

#4 Updated by Koichi Sasada almost 3 years ago

Matz, could you reply?

#5 Updated by Yukihiro Matsumoto almost 3 years ago

  • ruby -v changed from ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0] to -

Hi,

In message "Re: [Ruby 1.9 - Bug #4561] 1.9.2 requires parentheses around argument of method call in an array, where 1.8.7 did not"
on Sat, 11 Jun 2011 15:58:33 +0900, Koichi Sasada redmine@ruby-lang.org writes:

|Bug #4561: 1.9.2 requires parentheses around argument of method call in an array, where 1.8.7 did not
|http://redmine.ruby-lang.org/issues/4561
|
|Matz, could you reply?

It's an intentional syntax change in 1.9.

                        matz.

#6 Updated by Julian Raschke almost 3 years ago

Yukihiro Matsumoto wrote:

It's an intentional syntax change in 1.9.

I have run into the same issue today and wasn't sure if it was a bug or intentional. Nice to find both this issue and your recent response.

Out of curiosity, what is the reasoning behind this change? It seems a bit unintuitive that foo(bar 5) and {bar 5} work, even [bar { baz }], but [bar 5] not. All four are enclosed calls without parenthesis. Is there an ambiguity nearby that this syntax change is trying to clarify?

#7 Updated by Hiroshi Nakamura almost 3 years ago

  • Assignee changed from Yukihiro Matsumoto to Koichi Sasada
  • Target version set to 1.9.3

#8 Updated by Koichi Sasada almost 3 years ago

  • Status changed from Assigned to Closed

Also available in: Atom PDF