* enumerator.c (lazy_zip): raise error for bad arguments
[Bug #7706] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38926 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1af390b1ea
commit
aab2f788d7
@ -1,3 +1,8 @@
|
|||||||
|
Thu Jan 24 16:47:26 2013 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||||
|
|
||||||
|
* enumerator.c (lazy_zip): raise error for bad arguments
|
||||||
|
[Bug #7706]
|
||||||
|
|
||||||
Thu Jan 24 16:05:08 2013 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
Thu Jan 24 16:05:08 2013 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||||
|
|
||||||
* enumerator.c: Optimize Lazy#zip when passed only arrays
|
* enumerator.c: Optimize Lazy#zip when passed only arrays
|
||||||
|
@ -1663,6 +1663,12 @@ lazy_zip(int argc, VALUE *argv, VALUE obj)
|
|||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
v = rb_check_array_type(argv[i]);
|
v = rb_check_array_type(argv[i]);
|
||||||
if (NIL_P(v)) {
|
if (NIL_P(v)) {
|
||||||
|
for (; i < argc; i++) {
|
||||||
|
if (!rb_respond_to(argv[i], id_each)) {
|
||||||
|
rb_raise(rb_eTypeError, "wrong argument type %s (must respond to :each)",
|
||||||
|
rb_obj_classname(argv[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
ary = rb_ary_new4(argc, argv);
|
ary = rb_ary_new4(argc, argv);
|
||||||
func = lazy_zip_func;
|
func = lazy_zip_func;
|
||||||
break;
|
break;
|
||||||
|
@ -213,6 +213,11 @@ class TestLazyEnumerator < Test::Unit::TestCase
|
|||||||
assert_equal(1, a.current)
|
assert_equal(1, a.current)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_zip_bad_arg
|
||||||
|
a = Step.new(1..3)
|
||||||
|
assert_raise(TypeError){ a.lazy.zip(42) }
|
||||||
|
end
|
||||||
|
|
||||||
def test_zip_with_block
|
def test_zip_with_block
|
||||||
# zip should be eager when a block is given
|
# zip should be eager when a block is given
|
||||||
a = Step.new(1..3)
|
a = Step.new(1..3)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user