* insns.def (getinlinecache): Qnil is a valid value as a constant.
  this can be observable when accessing a deprecated constant
  which is nil.  non-nil constant is warned just once for each
  location, but every time if it is nil.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-02-10 16:54:47 +00:00
Родитель 7b6f0478e3
Коммит aea14e68fb
3 изменённых файлов: 20 добавлений и 9 удалений

Просмотреть файл

@ -951,10 +951,13 @@ getinlinecache
() ()
(VALUE val) (VALUE val)
{ {
val = vm_ic_hit_p(ic, GET_EP()); if (vm_ic_hit_p(ic, GET_EP())) {
if (val != Qnil) { val = ic->ic_value.value;
JUMP(dst); JUMP(dst);
} }
else {
val = Qnil;
}
} }
/* set inline cache */ /* set inline cache */

Просмотреть файл

@ -1429,6 +1429,17 @@ class TestModule < Test::Unit::TestCase
assert_warn(/deprecated/, bug12382) {c.class_eval "FOO"} assert_warn(/deprecated/, bug12382) {c.class_eval "FOO"}
end end
NIL = nil
FALSE = false
deprecate_constant(:NIL, :FALSE)
def test_deprecate_nil_constant
w = EnvUtil.verbose_warning {2.times {FALSE}}
assert_equal(1, w.scan("::FALSE").size, w)
w = EnvUtil.verbose_warning {2.times {NIL}}
assert_equal(1, w.scan("::NIL").size, w)
end
def test_constants_with_private_constant def test_constants_with_private_constant
assert_not_include(::TestModule.constants, :PrivateClass) assert_not_include(::TestModule.constants, :PrivateClass)
assert_not_include(::TestModule.constants(true), :PrivateClass) assert_not_include(::TestModule.constants(true), :PrivateClass)

Просмотреть файл

@ -3265,16 +3265,13 @@ vm_opt_newarray_min(rb_num_t num, const VALUE *ptr)
#undef id_cmp #undef id_cmp
static VALUE static int
vm_ic_hit_p(IC ic, const VALUE *reg_ep) vm_ic_hit_p(IC ic, const VALUE *reg_ep)
{ {
if (ic->ic_serial == GET_GLOBAL_CONSTANT_STATE() && if (ic->ic_serial == GET_GLOBAL_CONSTANT_STATE()) {
(ic->ic_cref == NULL || ic->ic_cref == rb_vm_get_cref(reg_ep))) { return (ic->ic_cref == NULL || ic->ic_cref == rb_vm_get_cref(reg_ep));
return ic->ic_value.value;
}
else {
return Qnil;
} }
return FALSE;
} }
static void static void