Skip to content

Commit cf87ee2

Browse files
authored
Merge pull request #544 from JuliaArrays/teh/dm2
Increase exception-type specificity for a few errors and tests
2 parents ceccb68 + 6770e41 commit cf87ee2

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

src/convert.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
(::Type{SA})(x::Tuple{Tuple{Tuple{<:Tuple}}}) where {SA <: StaticArray} = error("No precise constructor for $SA found. Length of input was $(length(x[1][1][1])).")
1+
(::Type{SA})(x::Tuple{Tuple{Tuple{<:Tuple}}}) where {SA <: StaticArray} =
2+
throw(DimensionMismatch("No precise constructor for $SA found. Length of input was $(length(x[1][1][1]))."))
23

34
@inline (::Type{SA})(x...) where {SA <: StaticArray} = SA(x)
45
@inline (::Type{SA})(a::StaticArray) where {SA<:StaticArray} = SA(Tuple(a))

test/FieldVector.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
@test [[Point3D(1.0,2.0,3.0)]; [Point3D(4.0,5.0,6.0)]]::Vector{Point3D} == [Point3D(1.0,2.0,3.0), Point3D(4.0,5.0,6.0)]
4141

4242
# Issue 342
43-
@test_throws ErrorException Point3D(1,2,3,4)
43+
@test_throws DimensionMismatch("No precise constructor for Point3D found. Length of input was 4.") Point3D(1,2,3,4)
4444
end
4545

4646
@testset "Mutable Point2D" begin

test/SDiagonal.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ using StaticArrays, Test, LinearAlgebra
5454
end
5555
end
5656

57-
@test_throws Exception m[5,5]
57+
@test_throws BoundsError m[5,5]
5858

59-
@test_throws Exception m[1,5]
59+
@test_throws BoundsError m[1,5]
6060

6161

6262
@test size(m) === (4, 4)

test/core.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
@testset "Type parameter errors" begin
2020
# (not sure what type of exception these should be?)
2121
@test_throws Exception SVector{1.0,Int}((1,))
22-
@test_throws Exception SVector{2,Int}((1,))
22+
@test_throws DimensionMismatch("No precise constructor for SArray{Tuple{2},$Int,1,2} found. Length of input was 1.") SVector{2,Int}((1,))
2323
@test_throws Exception SVector{1,3}((1,))
2424

2525
@test_throws Exception SMatrix{1.0,1,Int,1}((1,))
@@ -134,13 +134,13 @@
134134
@test @inferred(convert(Array{Int}, ma)) == a
135135
@test @inferred(convert(Array{Int,2}, ma)) == a
136136

137-
# broken, see https://github.com/JuliaArrays/StaticArrays.jl/pull/448#discussion_r197977273
138137
try
139138
convert(SVector, [1,2,3])
140139
catch err
141140
@test isa(err, ErrorException)
142141
@test startswith(err.msg, "The size of type")
143142
end
143+
@test_throws DimensionMismatch("expected input array of length 2, got length 3") convert(SVector{2}, [1,2,3])
144144
end
145145
@test_throws Exception Length{2.5}()
146146
@test Length(2) == Length{2}()

0 commit comments

Comments
 (0)