Modified: MacRuby/trunk/test-macruby/test_objc.rb (789 => 790)
--- MacRuby/trunk/test-macruby/test_objc.rb 2009-01-13 15:54:09 UTC (rev 789)
+++ MacRuby/trunk/test-macruby/test_objc.rb 2009-01-15 12:01:49 UTC (rev 790)
@@ -1,5 +1,30 @@
+#!/usr/bin/env macruby
+
require 'test/unit'
+require 'test/unit'
+class Test::Unit::TestCase
+ class << self
+ def it(name, &block)
+ define_method("test_#{name}", &block)
+ end
+ end
+end
+
+class TestClassConstantLookup < Test::Unit::TestCase
+ module Namespace
+ class PureRubyClass; end
+ end
+
+ it "should not find pure Ruby classes in different namespaces" do
+ assert_raise(NameError) { PureRubyClass }
+ end
+
+ it "should find pure Ruby class in different namespaces if given the correct path" do
+ assert_nothing_raised(NameError) { Namespace::PureRubyClass }
+ end
+end
+
class TestSubclass < Test::Unit::TestCase
def setup
Modified: MacRuby/trunk/variable.c (789 => 790)
--- MacRuby/trunk/variable.c 2009-01-13 15:54:09 UTC (rev 789)
+++ MacRuby/trunk/variable.c 2009-01-15 12:01:49 UTC (rev 790)
@@ -2086,10 +2086,20 @@
* 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).
+ *
+ * Note that objc_getClass does _not_ honor namespaces. Consider:
+ *
+ * module Namespace
+ * class RubyClass; end
+ * end
+ *
+ * In this case objc_getClass will happily return the Namespace::RubyClass
+ * object, which is ok but _not_ when trying to find a Ruby class. So we
+ * test whether or not the found class is a pure Ruby class or not.
*/
{
Class k = (Class)objc_getClass(rb_id2name(id));
- if (k != NULL)
+ if ((k != NULL) && (RCLASS_VERSION(k) != (RCLASS_IS_OBJECT_SUBCLASS | RCLASS_IS_RUBY_CLASS)))
return (VALUE)k;
}
#endif