Permalink
Browse files

merge revision(s) 66938: [Backport #15488]

	Fix `Module#const_defined?` on inherited constants

	[Fix GH-2061]

	From: manga_osyo <manga.osyo@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@66939 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
nurse committed Jan 29, 2019
1 parent df7ac8a commit bf8cc37b467e1d372e1b01b4d25e9ef6f8cc927f
Showing with 13 additions and 3 deletions.
  1. +0 −1 object.c
  2. +11 −0 test/ruby/test_module.rb
  3. +2 −2 version.h
@@ -2688,7 +2688,6 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
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",
@@ -338,6 +338,17 @@ def test_nested_defined_symbol
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')
@@ -1,10 +1,10 @@
#define RUBY_VERSION "2.6.1"
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 29
#define RUBY_PATCHLEVEL 30

#define RUBY_RELEASE_YEAR 2019
#define RUBY_RELEASE_MONTH 1
#define RUBY_RELEASE_DAY 26
#define RUBY_RELEASE_DAY 29

#include "ruby/version.h"

0 comments on commit bf8cc37

Please sign in to comment.