Skip to content

Commit

Permalink
Fix helpful warning on Julia 1.x
Browse files Browse the repository at this point in the history
Fixes #452
  • Loading branch information
timholy committed Oct 17, 2018
1 parent f445984 commit bfa5536
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/traits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ end

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

Size(a::T) where {T<:AbstractArray} = Size(T)
function Size(::Type{SA}) where {SA <: StaticArray} # A nice, default error message for when S not defined
function missing_size_error(::Type{SA}) where SA
error("""
The size of type `$SA` is not known.
Expand All @@ -83,7 +82,10 @@ function Size(::Type{SA}) where {SA <: StaticArray} # A nice, default error mess
SMatrix{3,3}(m) # correct - size is inferrable
""")
end
Size(::Type{SA}) where {SA <: StaticArray{S}} where {S<:Tuple} = Size(S) # S defined as a Tuple

Size(a::T) where {T<:AbstractArray} = Size(T)
Size(::Type{SA}) where {SA <: StaticArray} = missing_size_error(SA)
Size(::Type{SA}) where {SA <: StaticArray{S}} where {S<:Tuple} = @isdefined(S) ? Size(S) : missing_size_error(SA)
@pure Size(::Type{<:AbstractArray{<:Any, N}}) where {N} = Size(ntuple(_ -> Dynamic(), N))

struct Length{L}
Expand Down
4 changes: 2 additions & 2 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@
try
convert(SVector, [1,2,3])
catch err
@test_broken isa(err, ErrorException)
@test_broken startswith(err.msg, "The size of type `StaticArrays.SArray{Tuple{S},T,1,S} where T where S` is not known.")
@test isa(err, ErrorException)
@test startswith(err.msg, "The size of type")
end
end
@test_throws Exception Length{2.5}()
Expand Down

0 comments on commit bfa5536

Please sign in to comment.