Bug #4561
closed
1.9.2 requires parentheses around argument of method call in an array, where 1.8.7 did not
Added by dschweisguth (Dave Schweisguth) over 13 years ago.
Updated over 13 years ago.
Description
[dave hladik:~] cat method_call_without_parens_in_array.rb
def method_name(arg)
end
[ method_name 'value' ]
[dave hladik:~] ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10]
[dave hladik:~] ruby method_call_without_parens_in_array.rb
[dave hladik:~] rvm 1.9.2
[dave hladik:~] ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
[dave hladik:~] ruby method_call_without_parens_in_array.rb
method_call_without_parens_in_array.rb:4: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '('
[ method_name 'value' ]
^
method_call_without_parens_in_array.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_call_with_parens_in_array.rb
def method_name(arg)
end
[ method_name('value') ]
[dave hladik:~] ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10]
[dave hladik:~] ruby method_call_with_parens_in_array.rb
[dave hladik:~] rvm 1.9.2
[dave hladik:~] ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
[dave hladik:~] ruby method_call_with_parens_in_array.rb
no error¶
Files
=begin
Same thing with pre formatting:
[dave hladik:~] cat method_call_without_parens_in_array.rb
def method_name(arg)
end
[ method_name 'value' ]
[dave hladik:~] rvm system
[dave hladik:~] ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10]
[dave hladik:~] ruby method_call_without_parens_in_array.rb
[dave hladik:~] rvm 1.9.2
[dave hladik:~] ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
[dave hladik:~] ruby method_call_without_parens_in_array.rb
method_call_without_parens_in_array.rb:4: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '('
[ method_name 'value' ]
^
method_call_without_parens_in_array.rb:4: syntax error, unexpected ']', expecting $end
[dave hladik:~] cat method_call_with_parens_in_array.rb
def method_name(arg)
end
[ method_name('value') ]
[dave hladik:~] rvm system
[dave hladik:~] ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10]
[dave hladik:~] ruby method_call_with_parens_in_array.rb
[dave hladik:~] rvm 1.9.2
[dave hladik:~] ruby method_call_with_parens_in_array.rb
no error¶
=end
- Status changed from Open to Assigned
- Assignee set to matz (Yukihiro Matsumoto)
=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
- ruby -v changed from ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0] to -
Hi,
In message "Re: [ruby-core:36994] [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.
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?
- Assignee changed from matz (Yukihiro Matsumoto) to ko1 (Koichi Sasada)
- Target version set to 1.9.3
- Status changed from Assigned to Closed
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0Like0