Skip to content

Commit 8df9f26

Browse files
committed
defer error into function body
1 parent 924c632 commit 8df9f26

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/util.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ end
3939
@pure tuple_minimum(T::Tuple) = minimum(T)
4040

4141
# Something doesn't match up type wise
42-
function check_array_parameters(Size, T, N, L)
43-
(!isa(Size, DataType) || (Size.name !== Tuple.name)) && throw(ArgumentError("Static Array parameter Size must be a Tuple type, got $Size"))
44-
!isa(T, Type) && throw(ArgumentError("Static Array parameter T must be a type, got $T"))
45-
!isa(N.parameters[1], Int) && throw(ArgumenError("Static Array parameter N must be an integer, got $(N.parameters[1])"))
46-
!isa(L.parameters[1], Int) && throw(ArgumentError("Static Array parameter L must be an integer, got $(L.parameters[1])"))
42+
@generated function check_array_parameters(Size, T, N, L)
43+
(!isa(Size, DataType) || (Size.name !== Tuple.name)) && return :(throw(ArgumentError("Static Array parameter Size must be a Tuple type, got $Size")))
44+
!isa(T, Type) && return :(throw(ArgumentError("Static Array parameter T must be a type, got $T")))
45+
!isa(N.parameters[1], Int) && return :(throw(ArgumenError("Static Array parameter N must be an integer, got $(N.parameters[1])")))
46+
!isa(L.parameters[1], Int) && return :(throw(ArgumentError("Static Array parameter L must be an integer, got $(L.parameters[1])")))
4747
# shouldn't reach here. Anything else should have made it to the function below
48-
error("Internal error. Please file a bug")
48+
return :(error("Internal error. Please file a bug"))
4949
end
5050

5151
@generated function check_array_parameters{Size,T,N,L}(::Type{Size}, ::Type{T}, ::Type{Val{N}}, ::Type{Val{L}})
5252
if !all(x->isa(x, Int), Size.parameters)
53-
throw(ArgumentError("Static Array parameter Size must be a tuple of Ints (e.g. `SArray{Tuple{3,3}}` or `SMatrix{3,3}`)."))
53+
return :(throw(ArgumentError("Static Array parameter Size must be a tuple of Ints (e.g. `SArray{Tuple{3,3}}` or `SMatrix{3,3}`).")))
5454
end
5555

5656
if L != tuple_prod(Size) || L < 0 || tuple_minimum(Size) < 0 || tuple_length(Size) != N
57-
throw(ArgumentError("Size mismatch in Static Array parameters. Got size $Size, dimension $N and length $L."))
57+
return :(throw(ArgumentError("Size mismatch in Static Array parameters. Got size $Size, dimension $N and length $L.")))
5858
end
5959

6060
return nothing

0 commit comments

Comments
 (0)