Skip to content

Commit ad583c9

Browse files
authored
Resolve ambiguity for convert(::Type{<:Scalar}, ::StaticArray) (#808)
1 parent cee335d commit ad583c9

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/convert.jl

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
# this covers most conversions and "statically-sized reshapes"
1010
@inline convert(::Type{SA}, sa::StaticArray) where {SA<:StaticArray} = SA(Tuple(sa))
11+
@inline convert(::Type{SA}, sa::StaticArray) where {SA<:Scalar} = SA((sa[],)) # disambiguation
1112
@inline convert(::Type{SA}, sa::SA) where {SA<:StaticArray} = sa
1213
@inline convert(::Type{SA}, x::Tuple) where {SA<:StaticArray} = SA(x) # convert -> constructor. Hopefully no loops...
1314

test/ambiguities.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
const allowable_ambiguities =
55
if VERSION < v"1.1"
6-
4
6+
3
77
elseif VERSION < v"1.2"
8-
2
9-
else
108
1
9+
else
10+
0
1111
end
1212

1313
@test length(detect_ambiguities(Base, LinearAlgebra, StaticArrays)) <= allowable_ambiguities

test/convert.jl

+4
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ end # testset
1414
# Issue #651
1515
@testinf SVector{0,Float64}(Any[]) === SVector{0,Float64}()
1616
@testinf SVector{0,Float64}(Int8[]) === SVector{0,Float64}()
17+
18+
# PR #808
19+
@test Scalar{Int}[SVector{1,Int}(3), SVector{1,Float64}(2.0)] == [Scalar{Int}(3), Scalar{Int}(2)]
20+
@test Scalar[SVector{1,Int}(3), SVector{1,Float64}(2.0)] == [Scalar{Int}(3), Scalar{Float64}(2.0)]
1721
end

0 commit comments

Comments
 (0)