From cb92ed339c4ee511bab05954cc06bf7b0304257c Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 14 Oct 2022 13:49:48 +0400 Subject: [PATCH 1/2] type assertion in convert --- Project.toml | 2 +- src/OffsetArrays.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 799c5ac2..3a004fcc 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "OffsetArrays" uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" -version = "1.12.8" +version = "1.13.0" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/src/OffsetArrays.jl b/src/OffsetArrays.jl index ec446abe..4107d31b 100644 --- a/src/OffsetArrays.jl +++ b/src/OffsetArrays.jl @@ -253,7 +253,7 @@ end end @inline OffsetArray{T,N,A}(M::A; checkoverflow = false) where {T,N,A<:AbstractArray{T,N}} = OffsetArray{T,N,A}(M, ntuple(zero, Val(N)); checkoverflow = checkoverflow) -Base.convert(::Type{T}, M::AbstractArray) where {T<:OffsetArray} = M isa T ? M : T(M) +Base.convert(::Type{T}, M::AbstractArray) where {T<:OffsetArray} = M isa T ? M : T(M)::T @inline AbstractArray{T,N}(M::OffsetArray{S,N}) where {T,S,N} = OffsetArray{T}(M) From 88073a40cefa7995091b074cfbe804ae75c6d8cc Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 14 Oct 2022 13:56:38 +0400 Subject: [PATCH 2/2] Add test --- test/runtests.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 7cd56bfb..8ce0552e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -920,6 +920,12 @@ Base.Int(a::WeirdInteger) = a end end end + + @testset "convert" begin + m = zeros(1,1) + mo = @inferred (x -> convert(OffsetArray{Float64,2,Matrix{Float64}}, x[1]))(Any[m]) + @test mo == m + end end @testset "Axes supplied to constructor correspond to final result" begin