mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Made the warning for deprecated constants follow the category flag
This commit is contained in:
parent
76035e5bb6
commit
9bf9de3d9d
4 changed files with 28 additions and 9 deletions
22
error.c
22
error.c
|
@ -129,32 +129,38 @@ rb_syntax_error_append(VALUE exc, VALUE file, int line, int column,
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int warning_disabled_categories;
|
static unsigned int warning_disabled_categories;
|
||||||
#define RB_WARN_CATEGORY_DEPRECATED 1
|
|
||||||
|
|
||||||
static unsigned int
|
static unsigned int
|
||||||
rb_warning_category_mask(VALUE category)
|
rb_warning_category_mask(VALUE category)
|
||||||
{
|
{
|
||||||
unsigned int mask = 0;
|
return 1U << rb_warning_category_from_name(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
rb_warning_category_t
|
||||||
|
rb_warning_category_from_name(VALUE category)
|
||||||
|
{
|
||||||
|
rb_warning_category_t cat = RB_WARN_CATEGORY_NONE;
|
||||||
Check_Type(category, T_SYMBOL);
|
Check_Type(category, T_SYMBOL);
|
||||||
if (category == ID2SYM(rb_intern("deprecated"))) {
|
if (category == ID2SYM(rb_intern("deprecated"))) {
|
||||||
mask = RB_WARN_CATEGORY_DEPRECATED;
|
cat = RB_WARN_CATEGORY_DEPRECATED;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_raise(rb_eArgError, "unknown category: %"PRIsVALUE, category);
|
rb_raise(rb_eArgError, "unknown category: %"PRIsVALUE, category);
|
||||||
}
|
}
|
||||||
return mask;
|
return cat;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
MJIT_FUNC_EXPORTED bool
|
||||||
rb_warning_category_enabled_p(VALUE category)
|
rb_warning_category_enabled_p(rb_warning_category_t category)
|
||||||
{
|
{
|
||||||
return !(warning_disabled_categories & rb_warning_category_mask(category));
|
return !(warning_disabled_categories & (1U << category));
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_warning_s_aref(VALUE mod, VALUE category)
|
rb_warning_s_aref(VALUE mod, VALUE category)
|
||||||
{
|
{
|
||||||
if (rb_warning_category_enabled_p(category))
|
rb_warning_category_t cat = rb_warning_category_from_name(category);
|
||||||
|
if (rb_warning_category_enabled_p(cat))
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1554,6 +1554,13 @@ PRINTF_ARGS(void rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...), 2,
|
||||||
PRINTF_ARGS(void rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt, ...), 3, 4);
|
PRINTF_ARGS(void rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt, ...), 3, 4);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
RB_WARN_CATEGORY_NONE,
|
||||||
|
RB_WARN_CATEGORY_DEPRECATED,
|
||||||
|
} rb_warning_category_t;
|
||||||
|
rb_warning_category_t rb_warning_category_from_name(VALUE category);
|
||||||
|
bool rb_warning_category_enabled_p(rb_warning_category_t category);
|
||||||
|
|
||||||
#define rb_raise_cstr(etype, mesg) \
|
#define rb_raise_cstr(etype, mesg) \
|
||||||
rb_exc_raise(rb_exc_new_str(etype, rb_str_new_cstr(mesg)))
|
rb_exc_raise(rb_exc_new_str(etype, rb_str_new_cstr(mesg)))
|
||||||
#define rb_raise_static(etype, mesg) \
|
#define rb_raise_static(etype, mesg) \
|
||||||
|
|
|
@ -28,10 +28,13 @@ class TestModule < Test::Unit::TestCase
|
||||||
def setup
|
def setup
|
||||||
@verbose = $VERBOSE
|
@verbose = $VERBOSE
|
||||||
$VERBOSE = nil
|
$VERBOSE = nil
|
||||||
|
@deprecated = Warning[:deprecated]
|
||||||
|
Warning[:deprecated] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
$VERBOSE = @verbose
|
$VERBOSE = @verbose
|
||||||
|
Warning[:deprecated] = @deprecated
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_LT_0
|
def test_LT_0
|
||||||
|
@ -1580,6 +1583,8 @@ class TestModule < Test::Unit::TestCase
|
||||||
assert_warn(/#{c}::FOO is deprecated/) {Class.new(c)::FOO}
|
assert_warn(/#{c}::FOO is deprecated/) {Class.new(c)::FOO}
|
||||||
bug12382 = '[ruby-core:75505] [Bug #12382]'
|
bug12382 = '[ruby-core:75505] [Bug #12382]'
|
||||||
assert_warn(/deprecated/, bug12382) {c.class_eval "FOO"}
|
assert_warn(/deprecated/, bug12382) {c.class_eval "FOO"}
|
||||||
|
Warning[:deprecated] = false
|
||||||
|
assert_warn('') {c::FOO}
|
||||||
end
|
end
|
||||||
|
|
||||||
NIL = nil
|
NIL = nil
|
||||||
|
|
|
@ -2302,7 +2302,8 @@ rb_autoload_at_p(VALUE mod, ID id, int recur)
|
||||||
MJIT_FUNC_EXPORTED void
|
MJIT_FUNC_EXPORTED void
|
||||||
rb_const_warn_if_deprecated(const rb_const_entry_t *ce, VALUE klass, ID id)
|
rb_const_warn_if_deprecated(const rb_const_entry_t *ce, VALUE klass, ID id)
|
||||||
{
|
{
|
||||||
if (RB_CONST_DEPRECATED_P(ce)) {
|
if (RB_CONST_DEPRECATED_P(ce) &&
|
||||||
|
rb_warning_category_enabled_p(RB_WARN_CATEGORY_DEPRECATED)) {
|
||||||
if (klass == rb_cObject) {
|
if (klass == rb_cObject) {
|
||||||
rb_warn("constant ::%"PRIsVALUE" is deprecated", QUOTE_ID(id));
|
rb_warn("constant ::%"PRIsVALUE" is deprecated", QUOTE_ID(id));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue