summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--string.c6
-rw-r--r--test/ruby/test_string.rb13
3 files changed, 19 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index e377c9fd73..7a8e25a107 100644
--- a/NEWS
+++ b/NEWS
@@ -36,6 +36,9 @@ sufficient information, see the ChangeLog file or Redmine
ary[..3] # identical to ary[0..3]
where(sales: ..100)
+* Setting <code>$;</code> to non-nil value is warned now. Use of it in
+ String#split is warned too.
+
=== Core classes updates (outstanding ones only)
Enumerable::
diff --git a/string.c b/string.c
index 153fcc59b7..386c460740 100644
--- a/string.c
+++ b/string.c
@@ -7793,6 +7793,9 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
else if (!(spat = rb_fs_check(spat))) {
rb_raise(rb_eTypeError, "value of $; must be String or Regexp");
}
+ else {
+ rb_warn("$; is set to non-nil value");
+ }
if (split_type != awk) {
if (BUILTIN_TYPE(spat) == T_STRING) {
rb_encoding *enc2 = STR_ENC_GET(spat);
@@ -9918,6 +9921,9 @@ rb_fs_setter(VALUE val, ID id, VALUE *var)
"value of %"PRIsVALUE" must be String or Regexp",
rb_id2str(id));
}
+ if (!NIL_P(val)) {
+ rb_warn("non-nil $; will be deprecated");
+ }
*var = val;
}
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index f308cccbcd..d94c4da7ae 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -1702,7 +1702,7 @@ CODE
assert_equal([], "".split(//, 1))
ensure
- $; = fs
+ EnvUtil.suppress_warning {$; = fs}
end
def test_split_with_block
@@ -1742,7 +1742,7 @@ CODE
result = []; "".split(//, 1) {|s| result << s}
assert_equal([], result)
ensure
- $; = fs
+ EnvUtil.suppress_warning {$; = fs}
end
def test_fs
@@ -1750,7 +1750,7 @@ CODE
$; = []
}
- assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+ assert_separately(%W[-W0], "#{<<~"begin;"}\n#{<<~'end;'}")
bug = '[ruby-core:79582] $; must not be GCed'
begin;
$; = " "
@@ -1760,6 +1760,13 @@ CODE
GC.start
assert_equal([], "".split, bug)
end;
+
+ begin
+ fs = $;
+ assert_warn(/\$; will be deprecated/) {$; = " "}
+ ensure
+ EnvUtil.suppress_warning {$; = fs}
+ end
end
def test_split_encoding