Hash#[]= and Hash#store don't follow dup semantics for keys
-----------------------------------------------------------

                 Key: JRUBY-1605
                 URL: http://jira.codehaus.org/browse/JRUBY-1605
             Project: JRuby
          Issue Type: Bug
          Components: Core Classes/Modules
    Affects Versions: JRuby 1.x
         Environment: Ubuntu Linux 7.10
ruby 1.8.5 (2007-11-22 rev 4842) [i386-jruby1.1b1]

            Reporter: Vladimir Sizikov
            Priority: Minor
         Attachments: hash.diff

According to ruby-doc for Hash#store and Hash#[]=, "Key should not have its 
value changed while it is in use as a key (a String passed as a key will be 
duplicated and frozen)."

But JRuby doesn't follow the dup semantics for keys. Here's a small example:

key = "foo"
def key.reverse() "bar" end
h = {}
h[key] = 0
p h.keys[0].reverse == "oof"

MRI prints "true". JRuby prints "false". The sample code basically just 
verifies that singleton method
is not preserved once the string is used as a key in the hash, according to 
dup() behavior.

Also, this problem triggers two Rubinius spec failures:

#>time bin/mspec -t jruby spec/core/hash/

2)
Hash#[]= duplicates string keys using dup semantics FAILED
Expected "bar" to equal "oof":
/opt/work/rubinius/spec/mini_rspec.rb:217:in `=='
/opt/work/rubinius/./spec/core/hash/shared/store.rb:15:in `=='
/opt/work/rubinius/./spec/core/hash/shared/store.rb:9:in `it'
/opt/work/rubinius/spec/mini_rspec.rb:403:in `it'
/opt/work/rubinius/./spec/core/hash/shared/store.rb:9:in `it'
/opt/work/rubinius/./spec/core/hash/shared/store.rb:9:in `describe'
/opt/work/rubinius/spec/mini_rspec.rb:399:in `describe'
/opt/work/rubinius/./spec/core/hash/shared/store.rb:2:in `describe'
/opt/work/rubinius/./spec/core/hash/shared/store.rb:2:in `call'
/opt/work/rubinius/./spec/core/hash/../../spec_helper.rb:154:in 
`it_behaves_like'
/opt/work/rubinius/./spec/core/hash/element_set_spec.rb:6:in `it_behaves_like'
/opt/work/rubinius/./spec/core/hash/element_set_spec.rb:5:in `describe'
/opt/work/rubinius/spec/mini_rspec.rb:399:in `describe'
/opt/work/rubinius/./spec/core/hash/element_set_spec.rb:5:in `describe'
/opt/work/rubinius/./spec/core/hash/element_set_spec.rb:5:in `load'
last_mspec.rb:11:in `load'
last_mspec.rb:1:in `each'
last_mspec.rb:6:in `each'

6)
Hash#store duplicates string keys using dup semantics FAILED
Expected "bar" to equal "oof":
/opt/work/rubinius/spec/mini_rspec.rb:217:in `=='
/opt/work/rubinius/./spec/core/hash/shared/store.rb:15:in `=='
/opt/work/rubinius/./spec/core/hash/shared/store.rb:9:in `it'
/opt/work/rubinius/spec/mini_rspec.rb:403:in `it'
/opt/work/rubinius/./spec/core/hash/shared/store.rb:9:in `it'
/opt/work/rubinius/./spec/core/hash/shared/store.rb:9:in `describe'
/opt/work/rubinius/spec/mini_rspec.rb:399:in `describe'
/opt/work/rubinius/./spec/core/hash/shared/store.rb:2:in `describe'
/opt/work/rubinius/./spec/core/hash/shared/store.rb:2:in `call'
/opt/work/rubinius/./spec/core/hash/../../spec_helper.rb:154:in 
`it_behaves_like'
/opt/work/rubinius/./spec/core/hash/store_spec.rb:6:in `it_behaves_like'
/opt/work/rubinius/./spec/core/hash/store_spec.rb:5:in `describe'
/opt/work/rubinius/spec/mini_rspec.rb:399:in `describe'
/opt/work/rubinius/./spec/core/hash/store_spec.rb:5:in `describe'
/opt/work/rubinius/./spec/core/hash/store_spec.rb:5:in `load'
last_mspec.rb:11:in `load'
last_mspec.rb:1:in `each'
last_mspec.rb:6:in `each'


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to