Bug #2737: StringConstant +"string literal" (unspaced) raises exception
http://redmine.ruby-lang.org/issues/show/2737

Author: Joe Lapp
Status: Open, Priority: Low
ruby -v: 1.9.1p376

(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 `<main>'

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.


----------------------------------------
http://redmine.ruby-lang.org