1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

string.c: warn non-nil $;

* string.c (rb_str_split_m): warn use of non-nil $;.

* string.c (rb_fs_setter): warn when set to non-nil value.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2019-04-18 09:34:40 +00:00
parent eb3d3dfcc1
commit 4d1f86a1ff
3 changed files with 19 additions and 3 deletions

3
NEWS
View file

@ -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::

View file

@ -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;
}

View file

@ -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