diff --git a/base/tuple.jl b/base/tuple.jl index ac6cf64efb632..22e79940f61bb 100644 --- a/base/tuple.jl +++ b/base/tuple.jl @@ -467,17 +467,12 @@ reverse(t::Tuple) = revargs(t...) ## specialized reduction ## -# TODO: these definitions cannot yet be combined, since +(x...) -# where x might be any tuple matches too many methods. -# TODO: this is inconsistent with the regular sum in cases where the arguments -# require size promotion to system size. -sum(x::Tuple{Any, Vararg{Any}}) = +(x...) - -# NOTE: should remove, but often used on array sizes -# TODO: this is inconsistent with the regular prod in cases where the arguments -# require size promotion to system size. prod(x::Tuple{}) = 1 -prod(x::Tuple{Any, Vararg{Any}}) = *(x...) +# This is consistent with the regular prod because there is no need for size promotion +# if all elements in the tuple are of system size. +# It is defined here separately in order to support bootstrap, because it's needed earlier +# than the general prod definition is available. +prod(x::Tuple{Int, Vararg{Int}}) = *(x...) all(x::Tuple{}) = true all(x::Tuple{Bool}) = x[1] diff --git a/test/tuple.jl b/test/tuple.jl index 76c3f6257ac0c..86b0a11a8c913 100644 --- a/test/tuple.jl +++ b/test/tuple.jl @@ -347,6 +347,24 @@ end @test prod(()) === 1 @test prod((1,2,3)) === 6 + # issue 39182 + @test sum((0xe1, 0x1f)) === sum([0xe1, 0x1f]) + @test sum((Int8(3),)) === Int(3) + @test sum((UInt8(3),)) === UInt(3) + @test sum((3,)) === Int(3) + @test sum((3.0,)) === 3.0 + @test sum(("a",)) == sum(["a"]) + @test sum((0xe1, 0x1f), init=0x0) == sum([0xe1, 0x1f], init=0x0) + + # issue 39183 + @test prod((Int8(100), Int8(100))) === 10000 + @test prod((Int8(3),)) === Int(3) + @test prod((UInt8(3),)) === UInt(3) + @test prod((3,)) === Int(3) + @test prod((3.0,)) === 3.0 + @test prod(("a",)) == prod(["a"]) + @test prod((0xe1, 0x1f), init=0x1) == prod([0xe1, 0x1f], init=0x1) + @testset "all" begin @test all(()) === true @test all((false,)) === false