[前][次][番号順一覧][スレッド一覧]

ruby-changes:54721

From: nobu <ko1@a...>
Date: Mon, 28 Jan 2019 22:32:38 +0900 (JST)
Subject: [ruby-changes:54721] nobu:r66938 (trunk): Fix `Module#const_defined?` on inherited constants

nobu	2019-01-28 22:32:32 +0900 (Mon, 28 Jan 2019)

  New Revision: 66938

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66938

  Log:
    Fix `Module#const_defined?` on inherited constants
    
    [Fix GH-2061]
    
    From: manga_osyo <manga.osyo@g...>

  Modified files:
    trunk/object.c
    trunk/test/ruby/test_module.rb
Index: object.c
===================================================================
--- object.c	(revision 66937)
+++ object.c	(revision 66938)
@@ -2688,7 +2688,6 @@ rb_mod_const_defined(int argc, VALUE *ar https://github.com/ruby/ruby/blob/trunk/object.c#L2688
 		return Qfalse;
 	    mod = rb_const_get_at(mod, id);
 	}
-	recur = Qfalse;
 
 	if (p < pend && !RB_TYPE_P(mod, T_MODULE) && !RB_TYPE_P(mod, T_CLASS)) {
 	    rb_raise(rb_eTypeError, "%"PRIsVALUE" does not refer to class/module",
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 66937)
+++ test/ruby/test_module.rb	(revision 66938)
@@ -338,6 +338,17 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L338
     assert_raise(NameError) {self.class.const_defined?(const)}
   end
 
+  def test_nested_defined_inheritance
+    assert_send([Object, :const_defined?, [self.class.name, 'User', 'MIXIN'].join('::')])
+    assert_send([self.class, :const_defined?, 'User::MIXIN'])
+    assert_send([Object, :const_defined?, 'File::SEEK_SET'])
+
+    # const_defined? with `false`
+    assert_not_send([Object, :const_defined?, [self.class.name, 'User', 'MIXIN'].join('::'), false])
+    assert_not_send([self.class, :const_defined?, 'User::MIXIN', false])
+    assert_not_send([Object, :const_defined?, 'File::SEEK_SET', false])
+  end
+
   def test_nested_defined_bad_class
     assert_raise(TypeError) do
       self.class.const_defined?('User::USER::Foo')

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]