Skip to content

Commit ea08a81

Browse files
committed
Restrict &, | mr_empty fallbacks
1 parent 1877e6b commit ea08a81

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

base/process.jl

-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ setenv(cmd::Cmd; dir="") = Cmd(cmd; dir=dir)
230230
(&)(left::AbstractCmd, right::AbstractCmd) = AndCmds(left, right)
231231
redir_out(src::AbstractCmd, dest::AbstractCmd) = OrCmds(src, dest)
232232
redir_err(src::AbstractCmd, dest::AbstractCmd) = ErrOrCmds(src, dest)
233-
Base.mr_empty(f, op::typeof(&), T::Type{<:Base.AbstractCmd}) =
234-
throw(ArgumentError("reducing over an empty collection of type $T with operator & is not allowed"))
235233

236234
# Stream Redirects
237235
redir_out(dest::Redirectable, src::AbstractCmd) = CmdRedirect(src, dest, STDIN_NO)

base/reduce.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ mr_empty(::typeof(abs), op::typeof(scalarmax), T) = abs(zero(T))
239239
mr_empty(::typeof(abs2), op::typeof(scalarmax), T) = abs2(zero(T))
240240
mr_empty(::typeof(abs), op::typeof(max), T) = mr_empty(abs, scalarmax, T)
241241
mr_empty(::typeof(abs2), op::typeof(max), T) = mr_empty(abs2, scalarmax, T)
242-
mr_empty(f, op::typeof(&), T) = true
243-
mr_empty(f, op::typeof(|), T) = false
242+
mr_empty(::typeof(identity), op::typeof(&), ::Type{Bool}) = true
243+
mr_empty(::typeof(identity), op::typeof(|), ::Type{Bool}) = false
244244

245245
# Allow mr_empty to “see through” promote_sys_size
246246
let ComposedFunction = typename(typeof(identity identity)).wrapper

test/reduce.jl

+6-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
@test mapreduce(abs2, +, Float64[]) === 0.0
4949
@test mapreduce(abs2, Base.scalarmax, Float64[]) === 0.0
5050
@test mapreduce(abs, max, Float64[]) === 0.0
51-
@test mapreduce(abs2, &, Float64[]) === true
52-
@test mapreduce(abs2, |, Float64[]) === false
51+
@test_throws ArgumentError mapreduce(abs2, &, Float64[])
52+
@test_throws ArgumentError mapreduce(abs2, |, Float64[])
5353

5454
# mapreduce() type stability
5555
@test typeof(mapreduce(*, +, Int8[10])) ===
@@ -397,3 +397,7 @@ test18695(r) = sum( t^2 for t in r )
397397

398398
# issue #21107
399399
@test foldr(-,2:2) == 2
400+
401+
# test neutral element not picked incorrectly for &, |
402+
@test @inferred(foldl(&, Int[1])) === 1
403+
@test_throws ArgumentError foldl(&, Int[])

0 commit comments

Comments
 (0)