Skip to content

Commit 799da9c

Browse files
authored
Merge pull request #18140 from JuliaLang/forward-port-18105
Forward-port "Bugfix #18073 (#18105)"
2 parents bbb159e + 55e129e commit 799da9c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

base/reduce.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ any(f::Predicate, itr) = mapreduce_sc_impl(f, |, itr)
457457
any(f::typeof(identity), itr) =
458458
eltype(itr) <: Bool ?
459459
mapreduce_sc_impl(f, |, itr) :
460-
reduce(or_bool_only, itr)
460+
reduce(or_bool_only, false, itr)
461461

462462
"""
463463
all(p, itr) -> Bool
@@ -474,7 +474,7 @@ all(f::Predicate, itr) = mapreduce_sc_impl(f, &, itr)
474474
all(f::typeof(identity), itr) =
475475
eltype(itr) <: Bool ?
476476
mapreduce_sc_impl(f, &, itr) :
477-
reduce(and_bool_only, itr)
477+
reduce(and_bool_only, true, itr)
478478

479479
## in & contains
480480

test/reduce.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ prod2(itr) = invoke(prod, Tuple{Any}, itr)
173173

174174
# any & all
175175

176+
@test any([]) == false
176177
@test any(Bool[]) == false
177178
@test any([true]) == true
178179
@test any([false, false]) == false
@@ -183,6 +184,7 @@ prod2(itr) = invoke(prod, Tuple{Any}, itr)
183184
@test any([true, false, true]) == true
184185
@test any([false, false, false]) == false
185186

187+
@test all([]) == true
186188
@test all(Bool[]) == true
187189
@test all([true]) == true
188190
@test all([false, false]) == false
@@ -193,11 +195,13 @@ prod2(itr) = invoke(prod, Tuple{Any}, itr)
193195
@test all([true, false, true]) == false
194196
@test all([false, false, false]) == false
195197

198+
@test any(x->x>0, []) == false
196199
@test any(x->x>0, Int[]) == false
197200
@test any(x->x>0, [-3]) == false
198201
@test any(x->x>0, [4]) == true
199202
@test any(x->x>0, [-3, 4, 5]) == true
200203

204+
@test all(x->x>0, []) == true
201205
@test all(x->x>0, Int[]) == true
202206
@test all(x->x>0, [-3]) == false
203207
@test all(x->x>0, [4]) == true

0 commit comments

Comments
 (0)