Skip to content

Commit 4f5847c

Browse files
committed
Activate helpful error message for undefined-Size conversions
Adding `S<:Tuple` ensured a method would be higher in the methodtable.
1 parent 5a9c7f7 commit 4f5847c

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/traits.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ end
6868

6969
Base.show(io::IO, ::Size{S}) where {S} = print(io, "Size", S)
7070

71-
#= There seems to be a subtyping/specialization bug...
71+
Size(a::T) where {T<:AbstractArray} = Size(T)
7272
function Size(::Type{SA}) where {SA <: StaticArray} # A nice, default error message for when S not defined
7373
error("""
7474
The size of type `$SA` is not known.
@@ -82,9 +82,8 @@ function Size(::Type{SA}) where {SA <: StaticArray} # A nice, default error mess
8282
SMatrix(m) # this error
8383
SMatrix{3,3}(m) # correct - size is inferrable
8484
""")
85-
end =#
86-
Size(a::T) where {T<:AbstractArray} = Size(T)
87-
Size(::Type{<:StaticArray{S}}) where {S} = Size(S)
85+
end
86+
Size(::Type{SA}) where {SA <: StaticArray{S}} where {S<:Tuple} = Size(S) # S defined as a Tuple
8887
@pure Size(::Type{<:AbstractArray{<:Any, N}}) where {N} = Size(ntuple(_ -> Dynamic(), N))
8988

9089
struct Length{L}

test/core.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@
133133
@test @inferred(convert(Array, ma)) == a
134134
@test @inferred(convert(Array{Int}, ma)) == a
135135
@test @inferred(convert(Array{Int,2}, ma)) == a
136+
137+
try
138+
convert(SVector, [1,2,3])
139+
catch err
140+
@test isa(err, ErrorException)
141+
@test startswith(err.msg, "The size of type `StaticArrays.SArray{Tuple{S},T,1,S} where T where S` is not known.")
142+
end
136143
end
137144
@test_throws Exception Length{2.5}()
138145
@test Length(2) == Length{2}()

0 commit comments

Comments
 (0)