Bug #2737
closedStringConstant +"string literal" (unspaced) raises exception
Description
=begin
(I may have originally posted this in the wrong place. It also appears at http://redmine.ruby-lang.org/issues/show/2736)
When concatenating to a string constant, if a space does not follow '+' operator, Ruby raises an exception complaining that the unary '+' operator on strings is not defined.
The following code:
Konst = 'A'
Konst +'B'
...raises the following exception in IRB:
NoMethodError: undefined method +@' for "B":String from (irb):3 from /usr/local/bin/irb:12:in
'
Note that the following code -- adding a space after the '+' -- works as expected:
Konst = 'A'
Konst + 'B'
=> "AB"
The behavior appears to be a bug because the following does work as expected:
v = 'A'
v +'B'
=> "AB"
This also works:
'A' +'B'
=> "AB"
I discovered the problem when I changed working code by replacing an r-value variable with a constant. Replacing a literal or an r-value variable with a constant shouldn't break anything if the types match.
I found he problem in Ruby 1.9.1p376, but also reproduced it in 1.9.1p243. Friends are reporting that Ruby 1.8.7 (MRI) and JRuby 1.4 also have the problem.
=end