Skip to content

Commit d105393

Browse files
authored
Resolve ambiguities in similar and reshape (#307)
1 parent 4554c72 commit d105393

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/structarray.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,14 @@ for type in (
290290
:(Tuple{Union{Integer, AbstractUnitRange}, Vararg{Union{Integer, AbstractUnitRange}}}),
291291
# disambiguation with Base
292292
:(Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}}),
293+
:(Tuple{Integer, Vararg{Integer}}),
293294
)
294295
@eval function Base.similar(::Type{<:StructArray{T, N, C}}, sz::$(type)) where {T, N, C}
295296
return buildfromschema(typ -> similar(typ, sz), T, C)
296297
end
297298

298-
@eval function Base.similar(s::StructArray, S::Type, sz::$(type))
299-
return _similar(s, S, sz)
299+
@eval function Base.similar(s::StructArray, ::Type{T}, sz::$(type)) where {T}
300+
return _similar(s, T, sz)
300301
end
301302
end
302303

@@ -471,8 +472,9 @@ for type in (
471472
# mimic OffsetArrays signature
472473
:(Tuple{Union{Integer, AbstractUnitRange, Colon}, Vararg{Union{Integer, AbstractUnitRange, Colon}}}),
473474
# disambiguation with Base
475+
:(Tuple{Integer, Vararg{Integer}}),
474476
:(Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}}),
475-
:(Tuple{Vararg{Union{Colon, Integer}}}),
477+
:(Tuple{Union{Colon, Integer}, Vararg{Union{Colon, Integer}}}),
476478
:(Tuple{Vararg{Union{Colon, Int}}}),
477479
:(Tuple{Colon}),
478480
)

test/runtests.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ end
396396
@test s isa Matrix{Float32}
397397
@test size(s) == (2, 2)
398398

399+
s = similar(t, Float32, (Int8(2), 2))
400+
@test s isa Matrix{Float32}
401+
@test size(s) == (2, 2)
402+
399403
s = similar(t, Float32, 0:1, 2)
400404
@test s isa OffsetMatrix{Float32, Matrix{Float32}}
401405
@test axes(s) == (0:1, 1:2)
@@ -1043,6 +1047,8 @@ end
10431047
@test rs.a == [1 3; 2 4]
10441048
@test rs.b == ["a" "c"; "b" "d"]
10451049

1050+
@test reshape(s, (Int8(2), 2)) == reshape(s, (2, 2))
1051+
10461052
rs = reshape(s, (:,))
10471053
@test rs.a == s.a
10481054
@test rs.b == s.b
@@ -1630,5 +1636,5 @@ end
16301636
end
16311637

16321638
@testset "project quality" begin
1633-
Aqua.test_all(StructArrays, ambiguities=(; broken=true))
1639+
Aqua.test_all(StructArrays)
16341640
end

0 commit comments

Comments
 (0)