mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* parse.y (args): splat other than direct array literal.
[ruby-dev:39771] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@26160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
282a055612
commit
efe97f7f7b
3 changed files with 13 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Wed Dec 23 20:48:52 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* parse.y (args): splat other than direct array literal.
|
||||||
|
[ruby-dev:39771]
|
||||||
|
|
||||||
Wed Dec 23 17:23:52 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Dec 23 17:23:52 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* eval.c (rb_load): initialize orig_func. [ruby-core:27296]
|
* eval.c (rb_load): initialize orig_func. [ruby-core:27296]
|
||||||
|
|
10
parse.y
10
parse.y
|
@ -1455,7 +1455,7 @@ args : arg_value
|
||||||
| tSTAR arg_value
|
| tSTAR arg_value
|
||||||
{
|
{
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
$$ = splat_array($2);
|
if (!($$ = splat_array($2))) $$ = NEW_SPLAT($2);
|
||||||
/*%
|
/*%
|
||||||
$$ = arg_add_star(arg_new(), $2);
|
$$ = arg_add_star(arg_new(), $2);
|
||||||
%*/
|
%*/
|
||||||
|
@ -1569,14 +1569,15 @@ primary : literal
|
||||||
{
|
{
|
||||||
$$ = NEW_COLON3($2);
|
$$ = NEW_COLON3($2);
|
||||||
}
|
}
|
||||||
| tLBRACK aref_args ']'
|
| tLBRACK {$<num>$ = ruby_sourceline;} aref_args ']'
|
||||||
{
|
{
|
||||||
if ($2 == 0) {
|
if ($3 == 0) {
|
||||||
$$ = NEW_ZARRAY(); /* zero length array*/
|
$$ = NEW_ZARRAY(); /* zero length array*/
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$$ = $2;
|
$$ = $3;
|
||||||
}
|
}
|
||||||
|
nd_set_line($$, $<num>2);
|
||||||
}
|
}
|
||||||
| tLBRACE assoc_list '}'
|
| tLBRACE assoc_list '}'
|
||||||
{
|
{
|
||||||
|
@ -5312,6 +5313,7 @@ static NODE *
|
||||||
splat_array(node)
|
splat_array(node)
|
||||||
NODE* node;
|
NODE* node;
|
||||||
{
|
{
|
||||||
|
if (nd_type(node) == NODE_NEWLINE) node = node->nd_next;
|
||||||
if (nd_type(node) == NODE_SPLAT) node = node->nd_head;
|
if (nd_type(node) == NODE_SPLAT) node = node->nd_head;
|
||||||
if (nd_type(node) == NODE_ARRAY) return node;
|
if (nd_type(node) == NODE_ARRAY) return node;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1280,7 +1280,8 @@ class TestArray < Test::Unit::TestCase
|
||||||
def test_splat
|
def test_splat
|
||||||
a = [2,3]
|
a = [2,3]
|
||||||
assert_equal([1,2,3], [1, *a])
|
assert_equal([1,2,3], [1, *a])
|
||||||
|
bug2401 = '[ruby-dev:39771]'
|
||||||
a = [2,3]
|
a = [2,3]
|
||||||
assert_equal([2,3], [*a])
|
assert_equal([2,3], [*a], bug2401)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue