Skip to content

Commit

Permalink
Fix behavior of foldr on single-element arrays (JuliaLang#21497)
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Apr 23, 2017
1 parent 459797d commit 5955d79
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ foldl(op, itr) = mapfoldl(identity, op, itr)
function mapfoldr_impl(f, op, v0, itr, i::Integer)
# Unroll the while loop once; if v0 is known, the call to op may
# be evaluated at compile time
if isempty(itr)
if isempty(itr) || i == 0
return r_promote(op, v0)
else
x = itr[i]
Expand Down
1 change: 1 addition & 0 deletions test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@test foldr(+, Int16[]) === Int32(0)
@test foldr(-, 1:5) == 3
@test foldr(-, 10, 1:5) == -7
@test foldr(+, [1]) == 1 # Issue #21493

@test Base.mapfoldr(abs2, -, 2:5) == -14
@test Base.mapfoldr(abs2, -, 10, 2:5) == -4
Expand Down

0 comments on commit 5955d79

Please sign in to comment.