diff --git a/src/broadcast.jl b/src/broadcast.jl index 39bf91fc..33fe5336 100644 --- a/src/broadcast.jl +++ b/src/broadcast.jl @@ -125,12 +125,17 @@ scalar_getindex(x::Tuple{<: Any}) = x[1] end end - eltype_exprs = [t <: Union{AbstractArray, Ref} ? :(eltype($t)) : :($t) for t ∈ a] - newtype_expr = :(return_type(f, Tuple{$(eltype_exprs...)})) + if isempty(exprs) + eltype_exprs = [t <: Union{AbstractArray, Ref} ? :(eltype($t)) : :($t) for t ∈ a] + newtype_expr = :(return_type(f, Tuple{$(eltype_exprs...)})) + else + newtype_expr = :(eltype(vals)) + end return quote @_inline_meta - @inbounds return similar_type($first_staticarray, $newtype_expr, Size(newsize))(tuple($(exprs...))) + vals = tuple($(exprs...)) + @inbounds return similar_type($first_staticarray, $newtype_expr, Size(newsize))(vals) end end diff --git a/test/broadcast.jl b/test/broadcast.jl index 31e21200..7db6d8d0 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -151,22 +151,22 @@ end @testset "eltype after broadcast" begin # test cases issue #198 let a = SVector{4, Number}(2, 2.0, 4//2, 2+0im) - @test_broken eltype(a + 2) == Number - @test_broken eltype(a - 2) == Number - @test_broken eltype(a * 2) == Number - @test_broken eltype(a / 2) == Number + @test eltype(a + 2) == Number + @test eltype(a - 2) == Number + @test eltype(a * 2) == Number + @test eltype(a / 2) == Number end let a = SVector{3, Real}(2, 2.0, 4//2) - @test_broken eltype(a + 2) == Real - @test_broken eltype(a - 2) == Real - @test_broken eltype(a * 2) == Real - @test_broken eltype(a / 2) == Real + @test eltype(a + 2) == Real + @test eltype(a - 2) == Real + @test eltype(a * 2) == Real + @test eltype(a / 2) == Real end let a = SVector{3, Real}(2, 2.0, 4//2) - @test_broken eltype(a + 2.0) == Float64 - @test_broken eltype(a - 2.0) == Float64 - @test_broken eltype(a * 2.0) == Float64 - @test_broken eltype(a / 2.0) == Float64 + @test eltype(a + 2.0) == Float64 + @test eltype(a - 2.0) == Float64 + @test eltype(a * 2.0) == Float64 + @test eltype(a / 2.0) == Float64 end let a = broadcast(Float32, SVector(3, 4, 5)) @test eltype(a) == Float32 @@ -196,4 +196,10 @@ end d = SVector(1, 2, 3, 4) @test_throws DimensionMismatch a .= d end + + @testset "issue #493" begin + X = rand(SVector{3,SVector{2,Float64}}) + foo493(X) = normalize.(X) + @test foo493(X) isa Core.Compiler.return_type(foo493, Tuple{typeof(X)}) + end end