Skip to content

Commit 942a32f

Browse files
authored
make conversion of Length to Int safer (JuliaArrays#1175)
Now `Int(Length{StaticArraysCore.Dynamic()}())` throws a `MethodError` instead of returning a non-`Int` value. Some pieces of code that depended on the previous behavior are now adjusted. Bumped patch version to 1.6.2.
1 parent 162ecee commit 942a32f

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "StaticArrays"
22
uuid = "90137ffa-7385-5640-81b9-e52037218182"
3-
version = "1.6.1"
3+
version = "1.6.2"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/convert.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,16 @@ function construct_type(::Type{SA}, x) where {SA<:SizeEltypeAdaptable}
9090
error("Constructor for $SA is missing. Please file a bug.")
9191
end
9292

93+
adapt_size_impl1(::Type{SA}, ::Any, y::Int) where {SA<:StaticArray} = y
94+
adapt_size_impl1(::Type{SA}, x, ::Any) where {SA<:StaticArray} = _no_precise_size(SA, x)
95+
96+
adapt_size_impl0(::Type{SA}, x, ::Length{y}) where {SA<:StaticArray, y} = adapt_size_impl1(SA, x, y)
97+
9398
function adapt_size(::Type{SA}, x) where {SA<:StaticArray}
9499
if has_size(SA) && length_match_size(SA, x)
95100
SZ = Tuple{size(SA)...}
96101
else
97-
len = x isa Tuple ? length(x) : Int(Length(x))
102+
len = x isa Tuple ? length(x) : adapt_size_impl0(SA, x, Length(x))
98103
len isa Int || _no_precise_size(SA, x)
99104
if SA <: StaticVector
100105
SZ = Tuple{len}

src/traits.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Base.LinearIndices(::Size{S}) where {S} = LinearIndices(S)
6060
@pure size_tuple(::Size{S}) where {S} = Tuple{S...}
6161

6262
# Some @pure convenience functions for `Length`
63-
@pure (::Type{Int})(::Length{L}) where {L} = L
63+
@pure (::Type{Int})(::Length{L}) where {L} = Int(L)
6464

6565
@pure Base.:(==)(::Length{L}, l::Int) where {L} = L == l
6666
@pure Base.:(==)(l::Int, ::Length{L}) where {L} = l == L

0 commit comments

Comments
 (0)