From bfa5536913389884f3505e8571c41d3968c01577 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Wed, 17 Oct 2018 05:55:04 -0500 Subject: [PATCH] Fix helpful warning on Julia 1.x Fixes #452 --- src/traits.jl | 8 +++++--- test/core.jl | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/traits.jl b/src/traits.jl index e474ed8e..c6308cc9 100644 --- a/src/traits.jl +++ b/src/traits.jl @@ -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. @@ -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} diff --git a/test/core.jl b/test/core.jl index ca150126..02c568c3 100644 --- a/test/core.jl +++ b/test/core.jl @@ -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}()