Skip to content

Commit 3b1c73f

Browse files
authored
Fix constructor for SVector{0} from Array (#608)
Fixes #520
1 parent 3904426 commit 3b1c73f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/convert.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ end
2323
dimension_mismatch_fail(SA, a)
2424
end
2525

26-
return SA(unroll_tuple(a, Length(SA)))
26+
return _convert(SA, a, Length(SA))
2727
end
2828

29+
@inline _convert(SA, a, ::Length{L}) where L = SA(unroll_tuple(a, Length(SA)))
30+
@inline _convert(SA, a, ::Length{0}) = similar_type(SA, eltype(a))(())
31+
2932
length_val(a::T) where {T <: StaticArrayLike} = length_val(Size(T))
3033
length_val(a::Type{T}) where {T<:StaticArrayLike} = length_val(Size(T))
3134

test/convert.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ using StaticArrays, Test
55
SizeM = Size(2,2)(M)
66
@test typeof(SizeM)(SizeM).data === M
77
end # testset
8+
9+
@testset "Constructors of zero size arrays" begin
10+
# Issue #520
11+
@testinf SVector{0}(Int8[]) === SVector{0,Int8}()
12+
@testinf SMatrix{0,0}(zeros(0,0)) === SMatrix{0,0,Float64}(())
13+
end

0 commit comments

Comments
 (0)