Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan committed Oct 5, 2018
1 parent 3f4a404 commit e811fa6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,10 @@ function collect_to!(dest::AbstractArray{T}, itr, offs, st) where T
return collect_to!(new, itr, i+1, st)
end
end
i-1 < length(dest) &&
lastidx = lastindex(dest)
i-1 < lastidx &&
throw(ErrorException("iterator returned fewer elements than its declared length"))
i-1 > length(dest) &&
i-1 > lastidx &&
throw(ErrorException("iterator returned more elements than its declared length"))
return dest
end
Expand Down
7 changes: 4 additions & 3 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2546,7 +2546,8 @@ end
@test_throws ErrorException collect(InvalidIter2())
@test_throws ErrorException collect(Any, InvalidIter2())
@test_throws ErrorException collect(Int, InvalidIter2())
@test_throws ErrorException [x for x in InvalidIter2()]
# Should also throw ErrorException
@test_broken length(Int[x for x in InvalidIter2()]) != 2
# These cases cannot be tested without writing to invalid memory
# unless the function checked bounds on each iteration (#29458)
# @test_throws ErrorException [x for x in InvalidIter2()]
# @test_throws ErrorException Int[x for x in InvalidIter2()]
end

0 comments on commit e811fa6

Please sign in to comment.