Projects

Ticket #182 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

The constant lookup in MacRuby does not behave correctly

Reported by: vincent.isambart@… Owned by: lsansonetti@…
Priority: major Milestone:
Component: MacRuby Keywords:
Cc:

Description

MacRuby:

>> class A
>> class B
>> end
>> end
=> nil
>> B
=> A::B
>> 
>> A::B::B::B
=> A::B
>> 

Ruby 1.9:

irb(main):001:0> class A
irb(main):002:1> class B
irb(main):003:2> end
irb(main):004:1> end
=> nil
irb(main):005:0> B
NameError: uninitialized constant B
	from (irb):5
	from /usr/local/bin/irb-1.9:12:in `<main>'
irb(main):006:0>
irb(main):014:0> A::B::B::B
NameError: uninitialized constant A::B::B
	from (irb):14
	from /usr/local/bin/irb-1.9:12:in `<main>'

Change History

Changed 3 years ago by vincent.isambart@…

The problem is in variable.c, in rb_const_get_0:

    /* Classes are typically pre-loaded by Kernel#framework and imported by
     * rb_objc_resolve_const_value(), but it is still useful to keep the
     * dynamic import facility, because someone in the Objective-C world may
     * dynamically define classes at runtime (like ScriptingBridge.framework).
     */
    {
	Class k = (Class)objc_getClass(rb_id2name(id));
	if (k != NULL)
	    return (VALUE)k;
    }

You should keep this, but only return the class if it's not a Ruby class because if it's a Ruby class and you did not find it before, it's that it's in a different place in the namespace.

Changed 3 years ago by eloy.de.enige@…

Added failing test in r777

Changed 3 years ago by eloy.de.enige@…

  • status changed from new to closed
  • resolution set to fixed

Fixed in r790

Changed 3 years ago by eloy.de.enige@…

Well actually it was fixed in r791 for your example :)

Note: See TracTickets for help on using tickets.