Skip to content

Commit 21c5177

Browse files
committed
Resolve ambiguities in similar and reshape
1 parent b1836a6 commit 21c5177

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
@@ -289,13 +289,14 @@ for type in (
289289
:(Tuple{Union{Integer, AbstractUnitRange}, Vararg{Union{Integer, AbstractUnitRange}}}),
290290
# disambiguation with Base
291291
:(Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}}),
292+
:(Tuple{Integer, Vararg{Integer}}),
292293
)
293294
@eval function Base.similar(::Type{<:StructArray{T, N, C}}, sz::$(type)) where {T, N, C}
294295
return buildfromschema(typ -> similar(typ, sz), T, C)
295296
end
296297

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

@@ -470,8 +471,9 @@ for type in (
470471
# mimic OffsetArrays signature
471472
:(Tuple{Union{Integer, AbstractUnitRange, Colon}, Vararg{Union{Integer, AbstractUnitRange, Colon}}}),
472473
# disambiguation with Base
474+
:(Tuple{Integer, Vararg{Integer}}),
473475
:(Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}}),
474-
:(Tuple{Vararg{Union{Colon, Integer}}}),
476+
:(Tuple{Union{Colon, Integer}, Vararg{Union{Colon, Integer}}}),
475477
:(Tuple{Vararg{Union{Colon, Int}}}),
476478
:(Tuple{Colon}),
477479
)

test/runtests.jl

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

397+
s = similar(t, Float32, Int8(2), 2)
398+
@test s isa Matrix{Float32}
399+
@test size(s) == (2, 2)
400+
397401
s = similar(t, Float32, 0:1, 2)
398402
@test s isa OffsetMatrix{Float32, Matrix{Float32}}
399403
@test axes(s) == (0:1, 1:2)
@@ -1000,6 +1004,8 @@ end
10001004
@test rs.a == [1 3; 2 4]
10011005
@test rs.b == ["a" "c"; "b" "d"]
10021006

1007+
@test reshape(s, (Int8(2), 2)) == reshape(s, (2, 2))
1008+
10031009
rs = reshape(s, (:,))
10041010
@test rs.a == s.a
10051011
@test rs.b == s.b
@@ -1543,5 +1549,5 @@ end
15431549
end
15441550

15451551
@testset "project quality" begin
1546-
Aqua.test_all(StructArrays, ambiguities=(; broken=true))
1552+
Aqua.test_all(StructArrays)
15471553
end

0 commit comments

Comments
 (0)