[MacRuby] #246: NSMutableDictionary methods cannot retrieve values for Fixnum keys
#246: NSMutableDictionary methods cannot retrieve values for Fixnum keys ---------------------------------------+------------------------------------ Reporter: krishna.kotecha@… | Owner: lsansonetti@… Type: defect | Status: new Priority: critical | Milestone: Component: MacRuby | Keywords: NSMutableDictionary Hash ---------------------------------------+------------------------------------ In MacRuby 0.4 and current 0.5 build you can use Ruby syntax to work with Hashes: {{{ h = {} h[42] = "forty-two" puts h[42] # prints out "forty two" }}} This does not work if you use the NSMutatableDictionary method setObject:forKey: {{{ h = {} h.setObject 'fifty-three', forKey:53 h[53] # will return nil h.valueFor(53) # will cause MacRuby to crash }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/246> MacRuby <http://macruby.org/>
#246: NSMutableDictionary methods cannot retrieve values for Fixnum keys ---------------------------------------+------------------------------------ Reporter: krishna.kotecha@… | Owner: eloy.de.enige@… Type: defect | Status: new Priority: critical | Milestone: Component: MacRuby | Keywords: NSMutableDictionary Hash ---------------------------------------+------------------------------------ Changes (by eloy.de.enige@…): * owner: lsansonetti@… => eloy.de.enige@… Comment: Very nice, thanks! Will apply this asap. -- Ticket URL: <http://www.macruby.org/trac/ticket/246#comment:1> MacRuby <http://macruby.org/>
#246: NSMutableDictionary methods cannot retrieve values for Fixnum keys ---------------------------------------+------------------------------------ Reporter: krishna.kotecha@… | Owner: eloy.de.enige@… Type: defect | Status: new Priority: critical | Milestone: Component: MacRuby | Keywords: NSMutableDictionary Hash ---------------------------------------+------------------------------------ Comment(by krishna.kotecha@…): This bug was discovered whilst I was working through the MacRuby article on the (see: Mac Dev Center http://developer.apple.com/mac/articles/scriptingautomation/cocoaappswithmac...). The following is used as example code: {{{
h.setObject 'bar', :forKey => 43 => nil h => {42=>"foo", 43=>"bar"} }}}
And of course, trying the following causes much confusion to the newcomer: {{{
h[42] => nil }}}
-- Ticket URL: <http://www.macruby.org/trac/ticket/246#comment:2> MacRuby <http://macruby.org/>
#246: NSMutableDictionary methods cannot retrieve values for Fixnum keys ---------------------------------------+------------------------------------ Reporter: krishna.kotecha@… | Owner: eloy.de.enige@… Type: defect | Status: new Priority: critical | Milestone: Component: MacRuby | Keywords: NSMutableDictionary Hash ---------------------------------------+------------------------------------ Comment(by lsansonetti@…): I cannot reproduce the crash, however I reproduce the bug. {{{ $ macruby -e "h={}; h.setObject('foo',forKey:42); p h.objectForKey(42)" nil }}} I think this is because our Fixnum boxed class does not implement -[NSObject hash]. -- Ticket URL: <http://www.macruby.org/trac/ticket/246#comment:3> MacRuby <http://macruby.org/>
#246: NSMutableDictionary methods cannot retrieve values for Fixnum keys ---------------------------------------+------------------------------------ Reporter: krishna.kotecha@… | Owner: eloy.de.enige@… Type: defect | Status: closed Priority: critical | Milestone: MacRuby 0.6 Component: MacRuby | Resolution: fixed Keywords: NSMutableDictionary Hash | ---------------------------------------+------------------------------------ Changes (by lsansonetti@…): * status: new => closed * resolution: => fixed * milestone: => MacRuby 0.6 Comment: This has been fixed in trunk (I don't remember the exact revision). {{{ $ ./miniruby -e "h={}; h.setObject('foo',forKey:42); p h.objectForKey(42)" "foo" $ ./miniruby -e "h=NSMutableDictionary.dictionary; h.setObject('foo',forKey:42); p h.objectForKey(42)" "foo" }}} Closing. -- Ticket URL: <http://www.macruby.org/trac/ticket/246#comment:4> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby