Projects

Ticket #549 (closed defect: fixed)

Opened 2 years ago

Last modified 21 months ago

Class variables are not initialised properly.

Reported by: sorin.ionescu@… Owned by: lsansonetti@…
Priority: blocker Milestone: MacRuby 0.7
Component: MacRuby Keywords: class, instance
Cc:

Description (last modified by martinlagardette@…) (diff)

The mime-types gem has a class and an instance interface. The class interface uses an instance of itself. However, it doesn’t work in MacRuby. It does not seem to be initialised properly. I have included in a sample code with the expected behaviour. Changing @__types__ to @@__types__ will not fix it.

class MacRubyInitTest
  def initialize
    @foo = true
  end
  
  def add
    p self
    puts "@foo = " + @foo.inspect
  end

  @__types__ = self.new()

  def self.add
    @__types__.add
  end
end

t = MacRubyInitTest.new
t.add
MacRubyInitTest.add

Output (MacRuby 0.5)

<MacRubyInitTest:0x200024d80 @foo=true>
@foo = true
<MacRubyInitTest:0x200024e00 @foo=true>
@foo = nil

Expected (Ruby 1.9.1/1.8.7)

#<MacRubyInitTest:0x00000100847920 @foo=true>
@foo = true
#<MacRubyInitTest:0x00000100847a70 @foo=true>
@foo = true

Attachments

macruby_bug Download (401 bytes) - added by sorin.ionescu@… 2 years ago.

Change History

Changed 2 years ago by sorin.ionescu@…

Changed 2 years ago by sorin.ionescu@…

Trac totally butchered the code sample. DISREGARD IT AND SEE ATTACHMENT INSTEAD.

Changed 2 years ago by martinlagardette@…

  • description modified (diff)

Changed 2 years ago by martinlagardette@…

  • description modified (diff)

Changed 2 years ago by martinlagardette@…

  • description modified (diff)

Changed 2 years ago by martinlagardette@…

Hi Sorin! Thanks for the report. Are you sure, though, that this bug is a "blocker"?

To everyone: the attached file can be ignored, I edited the bug description to format the code, and modified it a little to show some interesting facts: p self shows that the @foo variable is set to true, however, @foo is nil.

Changed 2 years ago by sorin.ionescu@…

It is a blocker. The mime-types gem that uses it is quite popular if not the only one. Thanks for fixing the report.

Changed 21 months ago by lsansonetti@…

  • status changed from new to closed
  • resolution set to fixed
  • milestone changed from MacRuby 0.5 to MacRuby 0.7

This should be fixed in trunk (as least since r4119).

Note: See TracTickets for help on using tickets.