[MacRuby-devel] [MacRuby] #499: Order declaring class hierarchy gets MacRuby confused about instance variables

MacRuby ruby-noreply at macosforge.org
Thu Dec 10 17:48:18 PST 2009


#499: Order declaring class hierarchy gets MacRuby confused about instance
variables
------------------------------+---------------------------------------------
 Reporter:  paul@…            |       Owner:  lsansonetti@…        
     Type:  defect            |      Status:  new                  
 Priority:  major             |   Milestone:  MacRuby 0.5          
Component:  MacRuby           |    Keywords:                       
------------------------------+---------------------------------------------
 The following code appears to misbehave in MacRuby. It defines a class
 hierarchy Alpha > Beta > Gamma, with methods to set and get instance
 variables.

 {{{
 class Alpha
 end

 class Beta < Alpha
    def setAnotherVar
       @another_var = "Assigned to another_var in Beta"
    end
 end

 class Alpha
    def setVar=(var)
       @var = var
    end
    def var
       @var
    end
 end

 class Gamma < Beta
    def setAnotherVar
       @another_var = "Assigned to another_var in Gamma"
    end
 end

 a = Gamma.new
 a.setVar = "Assigned to var"
 puts a.var
 a.setAnotherVar
 puts a.var
 }}}

 Ruby 1.8.7 prints:

 Assigned to var[[BR]]
 Assigned to var

 Whereas MacRuby prints:

 Assigned to var[[BR]]
 Assigned to another_var in Gamma

 Ruby 1.8.7 would appear to be the correct behaviour. MacRuby is getting
 confused about instance variables. Setting the "another_var" instance
 variable wrongly changes the "var" instance variable.

 Declaring the classes strictly in the order of the hierarchy (i.e Alpha
 then Beta then Gamma) fixes the problem, but in a large project where
 classes are autoloaded, that may not happen.

 This is a simplified extraction from a larger project. It was a very
 elusive bug. Well, is it a bug?

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/499>
MacRuby <http://macruby.org/>



More information about the MacRuby-devel mailing list