diff --git a/test/broadcast.jl b/test/broadcast.jl index da8ef04a1e38b9..69b53b775ba1a4 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -311,7 +311,7 @@ end let f17314 = x -> x < 0 ? false : x @test eltype(broadcast(f17314, 1:3)) === Int @test eltype(broadcast(f17314, -1:1)) === Integer - @test eltype(broadcast(f17314, Int[])) === Any + @test eltype(broadcast(f17314, Int[])) === Union{Bool,Int} end let io = IOBuffer() broadcast(x->print(io,x), 1:5) # broadcast with side effects @@ -336,3 +336,18 @@ end @test broadcast(+, 1.0, (0, -2.0)) == (1.0,-1.0) @test broadcast(+, 1.0, (0, -2.0), [1]) == [2.0, 0.0] @test broadcast(*, ["Hello"], ", ", ["World"], "!") == ["Hello, World!"] + +# Ensure that even strange constructors that break `T(x)::T` work with broadcast +immutable StrangeType18623 end +StrangeType18623(x) = x +StrangeType18623(x,y) = (x,y) +@test @inferred broadcast(StrangeType18623, 1:3) == [1,2,3] +@test @inferred broadcast(StrangeType18623, 1:3, 4:6) == [(1,4),(2,5),(3,6)] + +@test typeof(Int.(Number[1, 2, 3])) === typeof((x->Int(x)).(Number[1, 2, 3])) + +@test @inferred broadcast(CartesianIndex, 1:2) == [CartesianIndex(1), CartesianIndex(2)] +@test @inferred broadcast(CartesianIndex, 1:2, 3:4) == [CartesianIndex(1,3), CartesianIndex(2,4)] + +# Issue 18622 +@test @inferred tuple.(1:3, 4:6, 7:9)::Vector{Tuple{Int,Int,Int}} == [(1,4,7), (2,5,8), (3,6,9)] diff --git a/test/numbers.jl b/test/numbers.jl index 4dcd91155d7eeb..48d97ad9e8fb5e 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -2806,21 +2806,21 @@ let types = (Base.BitInteger_types..., BigInt, Bool, Complex{Int}, Complex{UInt}, Complex32, Complex64, Complex128) for S in types for op in (+, -) - T = @inferred Base._promote_op(op, S) + T = @inferred Base.promote_op(op, S) t = @inferred op(one(S)) @test T === typeof(t) end for R in types for op in (+, -, *, /, ^) - T = @inferred Base._promote_op(op, S, R) + T = @inferred Base.promote_op(op, S, R) t = @inferred op(one(S), one(R)) @test T === typeof(t) end end end - @test @inferred(Base._promote_op(!, Bool)) === Bool + @test @inferred(Base.promote_op(!, Bool)) === Bool end let types = (Base.BitInteger_types..., BigInt, Bool, @@ -2828,20 +2828,20 @@ let types = (Base.BitInteger_types..., BigInt, Bool, Float16, Float32, Float64, BigFloat) for S in types, T in types for op in (<, >, <=, >=, (==)) - @test @inferred(Base._promote_op(op, S, T)) === Bool + @test @inferred(Base.promote_op(op, S, T)) === Bool end end end let types = (Base.BitInteger_types..., BigInt, Bool) for S in types - T = @inferred Base._promote_op(~, S) + T = @inferred Base.promote_op(~, S) t = @inferred ~one(S) @test T === typeof(t) for R in types for op in (&, |, <<, >>, (>>>), %, รท) - T = @inferred Base._promote_op(op, S, R) + T = @inferred Base.promote_op(op, S, R) t = @inferred op(one(S), one(R)) @test T === typeof(t) end