rubinius/rubinius — Issue #1599: string index behavior
Author: benknowles
Created: 2012-03-08 02:59:17+00:00
State: open

On MRI, the following behavior is present:

ruby-1.9.2-p290 :001 > a = ""
=> ""
ruby-1.9.2-p290 :002 > b = ""
=> ""
ruby-1.9.2-p290 :003 > a[0] = "h"
=> "h"
ruby-1.9.2-p290 :004 > b[1] = "h"
IndexError: index 1 out of string
from (irb):4:in `[]='
from (irb):4
from /home/ben/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `

'

Writing to index 0 on an empty string is valid, while >= 1 throws an index error.

On Rubinius:

a = ""
a[0] = "h"

Gives:

An exception occurred running bacon.rb
index 0 out of string (IndexError)

Backtrace:
String#[]= at kernel/common/string.rb:319
Object#__script__ at bacon.rb:2
Rubinius::CodeLoader#load_script at kernel/delta/codeloader.rb:67
Rubinius::CodeLoader.load_script at kernel/delta/codeloader.rb:109
Rubinius::Loader#script at kernel/loader.rb:630
Rubinius::Loader#main at kernel/loader.rb:834