Hoisted out undefined_constant

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-12-28 10:33:02 +00:00
parent f826cde5a9
commit d54a86d49d

View File

@ -2566,6 +2566,14 @@ rb_public_const_get_at(VALUE klass, ID id)
return rb_const_get_0(klass, id, TRUE, FALSE, TRUE); return rb_const_get_0(klass, id, TRUE, FALSE, TRUE);
} }
NORETURN(static void undefined_constant(VALUE mod, VALUE name));
static void
undefined_constant(VALUE mod, VALUE name)
{
rb_name_err_raise("constant %2$s::%1$s not defined",
mod, name);
}
/* /*
* call-seq: * call-seq:
* remove_const(sym) -> obj * remove_const(sym) -> obj
@ -2582,8 +2590,7 @@ rb_mod_remove_const(VALUE mod, VALUE name)
const ID id = id_for_var(mod, name, a, constant); const ID id = id_for_var(mod, name, a, constant);
if (!id) { if (!id) {
rb_name_err_raise("constant %2$s::%1$s not defined", undefined_constant(mod, name);
mod, name);
} }
return rb_const_remove(mod, id); return rb_const_remove(mod, id);
} }
@ -2601,8 +2608,7 @@ rb_const_remove(VALUE mod, ID id)
rb_name_err_raise("cannot remove %2$s::%1$s", rb_name_err_raise("cannot remove %2$s::%1$s",
mod, ID2SYM(id)); mod, ID2SYM(id));
} }
rb_name_err_raise("constant %2$s::%1$s not defined", undefined_constant(mod, ID2SYM(id));
mod, ID2SYM(id));
} }
rb_clear_constant_cache(); rb_clear_constant_cache();
@ -2988,8 +2994,7 @@ set_const_visibility(VALUE mod, int argc, const VALUE *argv,
rb_clear_constant_cache(); rb_clear_constant_cache();
} }
rb_name_err_raise("constant %2$s::%1$s not defined", undefined_constant(mod, val);
mod, val);
} }
if ((ce = rb_const_lookup(mod, id))) { if ((ce = rb_const_lookup(mod, id))) {
ce->flag &= ~mask; ce->flag &= ~mask;
@ -3008,8 +3013,7 @@ set_const_visibility(VALUE mod, int argc, const VALUE *argv,
if (i > 0) { if (i > 0) {
rb_clear_constant_cache(); rb_clear_constant_cache();
} }
rb_name_err_raise("constant %2$s::%1$s not defined", undefined_constant(mod, ID2SYM(id));
mod, ID2SYM(id));
} }
} }
rb_clear_constant_cache(); rb_clear_constant_cache();
@ -3023,10 +3027,11 @@ rb_deprecate_constant(VALUE mod, const char *name)
long len = strlen(name); long len = strlen(name);
rb_class_modify_check(mod); rb_class_modify_check(mod);
if (!(id = rb_check_id_cstr(name, len, NULL)) || if (!(id = rb_check_id_cstr(name, len, NULL))) {
!(ce = rb_const_lookup(mod, id))) { undefined_constant(mod, rb_fstring_new(name, len));
rb_name_err_raise("constant %2$s::%1$s not defined", }
mod, rb_fstring_new(name, len)); if (!(ce = rb_const_lookup(mod, id))) {
undefined_constant(mod, ID2SYM(id));
} }
ce->flag |= CONST_DEPRECATED; ce->flag |= CONST_DEPRECATED;
} }