Project

General

Profile

Actions

Bug #7539

closed

Misleading error message "can't convert nil into string"

Added by connec (Chris Connelly) about 12 years ago. Updated almost 12 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
Backport:
[ruby-core:50733]

Description

When trying to call String#+ with nil as an argument, you get the error "can't convert nil into String", which does not make sense (in fact seeming blatantly false) as nil.to_s, String(nil) etc. all return '' without errors.

Ideally, this method should use to_s to convert the argument, or else report an error along the lines of "can't append nil to string".

Minimal test case:

Actual:
> '' + nil
TypeError: can't convert nil into String

Expected:
> '' + nil
''


Files

patch#7539.txt (583 Bytes) patch#7539.txt duerst (Martin Dürst), 12/11/2012 01:49 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0