зеркало из https://github.com/github/ruby.git
compile.c: non-destructive keyword splat
* compile.c (compile_array_): make copy a first hash not to modify the argument itself. keyword splat should be non-destructive. [ruby-core:62161] [Bug #9776] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
3bd10c6ee7
Коммит
37e432b5bf
|
@ -1,3 +1,9 @@
|
||||||
|
Sat Apr 26 10:55:33 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* compile.c (compile_array_): make copy a first hash not to modify
|
||||||
|
the argument itself. keyword splat should be non-destructive.
|
||||||
|
[ruby-core:62161] [Bug #9776]
|
||||||
|
|
||||||
Sat Apr 26 08:05:36 2014 Tanaka Akira <akr@fsij.org>
|
Sat Apr 26 08:05:36 2014 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* test/ruby/test_process.rb (test_rlimit_nofile): Don't limit
|
* test/ruby/test_process.rb (test_rlimit_nofile): Don't limit
|
||||||
|
|
|
@ -2479,6 +2479,7 @@ compile_array_(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE* node_root,
|
||||||
if (i > 0 || !first) ADD_INSN(ret, line, swap);
|
if (i > 0 || !first) ADD_INSN(ret, line, swap);
|
||||||
COMPILE(ret, "keyword splat", kw);
|
COMPILE(ret, "keyword splat", kw);
|
||||||
ADD_SEND(ret, line, ID2SYM(id_core_hash_merge_kwd), nhash);
|
ADD_SEND(ret, line, ID2SYM(id_core_hash_merge_kwd), nhash);
|
||||||
|
if (nhash == INT2FIX(1)) ADD_SEND(ret, line, ID2SYM(rb_intern("dup")), INT2FIX(0));
|
||||||
}
|
}
|
||||||
first = 0;
|
first = 0;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -439,6 +439,19 @@ class TestKeywordArguments < Test::Unit::TestCase
|
||||||
assert_equal([1, 2, 1, [], {:f=>5}, 2, {}], a.new.foo(1, 2, f:5), bug8993)
|
assert_equal([1, 2, 1, [], {:f=>5}, 2, {}], a.new.foo(1, 2, f:5), bug8993)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_splat_keyword_nondestructive
|
||||||
|
bug9776 = '[ruby-core:62161] [Bug #9776]'
|
||||||
|
|
||||||
|
h = {a: 1}
|
||||||
|
assert_equal({a:1, b:2}, {**h, b:2})
|
||||||
|
assert_equal({a:1}, h, bug9776)
|
||||||
|
|
||||||
|
pr = proc {|**opt| next opt}
|
||||||
|
assert_equal({a: 1}, pr.call(**h))
|
||||||
|
assert_equal({a: 1, b: 2}, pr.call(**h, b: 2))
|
||||||
|
assert_equal({a: 1}, h, bug9776)
|
||||||
|
end
|
||||||
|
|
||||||
def test_gced_object_in_stack
|
def test_gced_object_in_stack
|
||||||
bug8964 = '[ruby-dev:47729] [Bug #8964]'
|
bug8964 = '[ruby-dev:47729] [Bug #8964]'
|
||||||
assert_normal_exit %q{
|
assert_normal_exit %q{
|
||||||
|
|
Загрузка…
Ссылка в новой задаче