Skip to content

Commit 4aba375

Browse files
authored
similar(T, axes) does not accept colons (#165)
1 parent c841a99 commit 4aba375

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/OffsetArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ Base.reshape(A::OffsetVector, ::Colon) = A
234234
Base.reshape(A::OffsetArray, inds::Union{Int,Colon}...) = reshape(parent(A), inds)
235235
Base.reshape(A::OffsetArray, inds::Tuple{Vararg{Union{Int,Colon}}}) = reshape(parent(A), inds)
236236

237-
function Base.similar(::Type{T}, shape::Tuple{OffsetAxis,Vararg{OffsetAxis}}) where {T<:AbstractArray}
237+
function Base.similar(::Type{T}, shape::Tuple{OffsetAxisKnownLength,Vararg{OffsetAxisKnownLength}}) where {T<:AbstractArray}
238238
P = T(undef, map(_indexlength, shape))
239239
OffsetArray(P, map(_offset, axes(P), shape))
240240
end

test/runtests.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,22 @@ end
969969
@test_throws MethodError similar(A, (: ,2))
970970
@test_throws MethodError similar(A, Float64, (: ,:))
971971
@test_throws MethodError similar(A, Float64, (: ,2))
972+
973+
function testsimilar(args...)
974+
try
975+
similar(args...)
976+
catch e
977+
@test e isa MethodError
978+
io = IOBuffer()
979+
showerror(io, e)
980+
s = split(String(take!(io)),'\n')[1]
981+
@test occursin(repr(similar), s)
982+
end
983+
end
984+
985+
testsimilar(typeof(A), (:, :))
986+
testsimilar(typeof(A), (:, 2))
987+
testsimilar(typeof(A), (:, 1:3))
972988
end
973989

974990
@testset "reshape" begin

0 commit comments

Comments
 (0)