Skip to content

Commit 9c777f2

Browse files
committed
[Bug #20900] Warn deprecated constant when removing
1 parent 727b2a2 commit 9c777f2

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

spec/ruby/core/module/deprecate_constant_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@
4444
end
4545
end
4646

47+
ruby_bug '#20900', ''...'3.4' do
48+
describe "when removing the deprecated module" do
49+
it "warns with a message" do
50+
@module.deprecate_constant :PUBLIC1
51+
-> { @module.module_eval {remove_const :PUBLIC1} }.should complain(/warning: constant .+::PUBLIC1 is deprecated/)
52+
end
53+
end
54+
end
55+
4756
it "accepts multiple symbols and strings as constant names" do
4857
@module.deprecate_constant "PUBLIC1", :PUBLIC2
4958

test/ruby/test_module.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,9 +2148,8 @@ def test_deprecate_constant
21482148
Warning[:deprecated] = false
21492149
Class.new(c)::FOO
21502150
end
2151-
assert_warn('') do
2152-
Warning[:deprecated] = false
2153-
c.class_eval "FOO"
2151+
assert_warn(/deprecated/) do
2152+
c.class_eval {remove_const "FOO"}
21542153
end
21552154
end
21562155

variable.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3280,6 +3280,7 @@ rb_const_remove(VALUE mod, ID id)
32803280
undefined_constant(mod, ID2SYM(id));
32813281
}
32823282

3283+
rb_const_warn_if_deprecated(ce, mod, id);
32833284
rb_clear_constant_cache_for_id(id);
32843285

32853286
val = ce->value;

0 commit comments

Comments
 (0)