Project

General

Profile

Actions

Bug #2737

closed

StringConstant +"string literal" (unspaced) raises exception

Added by jtlapp (Joe Lapp) about 14 years ago. Updated almost 13 years ago.

Status:
Rejected
Assignee:
-
ruby -v:
1.9.1p376
[ruby-core:28147]

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0