Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
08a1dd2a
Commit
08a1dd2a
authored
Sep 08, 2016
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Sep 08, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3207 from ksss/splat
Fix SEGV when splat object
parents
cd5133c5
d4670223
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
3 deletions
+50
-3
src/array.c
src/array.c
+20
-3
test/t/syntax.rb
test/t/syntax.rb
+30
-0
No files found.
src/array.c
View file @
08a1dd2a
...
...
@@ -891,15 +891,32 @@ mrb_ary_rindex_m(mrb_state *mrb, mrb_value self)
MRB_API
mrb_value
mrb_ary_splat
(
mrb_state
*
mrb
,
mrb_value
v
)
{
mrb_value
a
,
recv_class
;
if
(
mrb_array_p
(
v
))
{
return
v
;
}
if
(
mrb_respond_to
(
mrb
,
v
,
mrb_intern_lit
(
mrb
,
"to_a"
)))
{
return
mrb_funcall
(
mrb
,
v
,
"to_a"
,
0
);
if
(
!
mrb_respond_to
(
mrb
,
v
,
mrb_intern_lit
(
mrb
,
"to_a"
)))
{
return
mrb_ary_new_from_values
(
mrb
,
1
,
&
v
);
}
else
{
a
=
mrb_funcall
(
mrb
,
v
,
"to_a"
,
0
);
if
(
mrb_array_p
(
a
))
{
return
a
;
}
else
if
(
mrb_nil_p
(
a
))
{
return
mrb_ary_new_from_values
(
mrb
,
1
,
&
v
);
}
else
{
recv_class
=
mrb_obj_value
(
mrb_obj_class
(
mrb
,
v
));
mrb_raisef
(
mrb
,
E_TYPE_ERROR
,
"can't convert %S to Array (%S#to_a gives %S)"
,
recv_class
,
recv_class
,
mrb_obj_value
(
mrb_obj_class
(
mrb
,
a
))
);
return
mrb_undef_value
();
}
}
static
mrb_value
...
...
test/t/syntax.rb
View file @
08a1dd2a
...
...
@@ -307,6 +307,36 @@ assert('Return values of no expression case statement') do
assert_equal
1
,
when_value
end
assert
(
'splat object in assignment'
)
do
o
=
Object
.
new
def
o
.
to_a
nil
end
assert_equal
[
o
],
(
a
=
*
o
)
def
o
.
to_a
1
end
assert_raise
(
TypeError
)
{
a
=
*
o
}
def
o
.
to_a
[
2
]
end
assert_equal
[
2
],
(
a
=
*
o
)
end
assert
(
'splat object in case statement'
)
do
o
=
Object
.
new
def
o
.
to_a
nil
end
a
=
case
o
when
*
o
1
end
assert_equal
1
,
a
end
assert
(
'splat in case statement'
)
do
values
=
[
3
,
5
,
1
,
7
,
8
]
testa
=
[
1
,
2
,
7
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment