Refine non-nil warnings for the deprecated variables

This commit is contained in:
Nobuyoshi Nakada 2025-12-05 01:04:08 +09:00
parent cf12aff059
commit 29a12297c3
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465
3 changed files with 19 additions and 9 deletions

View File

@ -11378,7 +11378,7 @@ rb_str_setter(VALUE val, ID id, VALUE *var)
static void
nil_setter_warning(ID id)
{
rb_warn_deprecated("'%"PRIsVALUE"'", NULL, rb_id2str(id));
rb_warn_deprecated("non-nil '%"PRIsVALUE"'", NULL, rb_id2str(id));
}
void

View File

@ -2907,10 +2907,10 @@ class TestIO < Test::Unit::TestCase
end
def test_print_separators
EnvUtil.suppress_warning {
$, = ':'
$\ = "\n"
}
assert_deprecated_warning(/non-nil '\$,'/) {$, = ":"}
assert_raise(TypeError) {$, = 1}
assert_deprecated_warning(/non-nil '\$\\'/) {$\ = "\n"}
assert_raise(TypeError) {$/ = 1}
pipe(proc do |w|
w.print('a')
EnvUtil.suppress_warning {w.print('a','b','c')}

View File

@ -1883,9 +1883,13 @@ CODE
def test_fs
return unless @cls == String
assert_raise_with_message(TypeError, /\$;/) {
$; = []
}
begin
fs = $;
assert_deprecated_warning(/non-nil '\$;'/) {$; = "x"}
assert_raise_with_message(TypeError, /\$;/) {$; = []}
ensure
EnvUtil.suppress_warning {$; = fs}
end
name = "\u{5206 5217}"
assert_separately([], "#{<<~"do;"}\n#{<<~"end;"}")
do;
@ -2775,7 +2779,13 @@ CODE
def test_rs
return unless @cls == String
assert_raise(TypeError) { $/ = 1 }
begin
rs = $/
assert_deprecated_warning(/non-nil '\$\/'/) { $/ = "" }
assert_raise(TypeError) { $/ = 1 }
ensure
EnvUtil.suppress_warning { $/ = rs }
end
name = "\u{5206 884c}"
assert_separately([], "#{<<~"do;"}\n#{<<~"end;"}")
do;