Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ end
return _convert(SA, a, Length(SA))
end

@inline _convert(SA, a, ::Length{L}) where L = SA(unroll_tuple(a, Length(SA)))
@inline _convert(SA, a, l::Length) = SA(unroll_tuple(a, l))
@inline _convert(SA::Type{<:StaticArray{<:Tuple,T}}, a, ::Length{0}) where T = similar_type(SA, T)(())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect a type assertion would be good here (that the output is indeeed an SA).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do that. Which error condition are you trying to cover, is it protection for the user to avoid stack overflows when they have a broken similar_type (constructor calling _convert calling constructor etc) or some such?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just guarding against the case that similar_type(SA) isn’t an SA (like rotations) which means constructors and conversion might return a rather surprising result.

@inline _convert(SA, a, ::Length{0}) = similar_type(SA, eltype(a))(())

length_val(a::T) where {T <: StaticArrayLike} = length_val(Size(T))
Expand Down
4 changes: 4 additions & 0 deletions test/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ end # testset
# Issue #520
@testinf SVector{0}(Int8[]) === SVector{0,Int8}()
@testinf SMatrix{0,0}(zeros(0,0)) === SMatrix{0,0,Float64}(())

# Issue #651
@testinf SVector{0,Float64}(Any[]) === SVector{0,Float64}()
@testinf SVector{0,Float64}(Int8[]) === SVector{0,Float64}()
end