Skip to content

Commit b64ab9c

Browse files
committed
infer constructors and add test for it
1 parent b577022 commit b64ab9c

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
language: julia
33
os:
44
- linux
5-
#- osx
5+
- osx
66
julia:
7-
#- 0.6
7+
- 1.0
88
- nightly
99
notifications:
1010
email: false

src/structarray.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ end
4141

4242
setindex!(s::StructArray, val, I::Int...) = set_ith!(s, val, I...)
4343

44-
fields(T) = fieldnames(T)
4544
fields(::Type{<:NamedTuple{K}}) where {K} = K
4645
fields(::Type{<:StructArray{T}}) where {T} = fields(T)
4746

47+
@generated function fields(t::Type{T}) where {T}
48+
return :($(Expr(:tuple, [QuoteNode(f) for f in fieldnames(T)]...)))
49+
end
50+
4851
@generated function push!(s::StructArray{T, 1}, vals) where {T}
4952
args = []
5053
for key in fields(T)

test/runtests.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ end
2626
@test t == StructArray{Pair}([3, 5, 2, 3, 5, 2], ["a", "b", "c", "a", "b", "c"])
2727
t = StructArray{Pair}([3, 5], ["a", "b"])
2828
t2 = StructArray{Pair}([1, 6], ["a", "b"])
29-
@test cat(1, t, t2) == StructArray{Pair}([3, 5, 1, 6], ["a", "b", "a", "b"]) == vcat(t, t2)
29+
@test cat(t, t2; dims=1) == StructArray{Pair}([3, 5, 1, 6], ["a", "b", "a", "b"]) == vcat(t, t2)
3030
@test vcat(t, t2) isa StructArray
31-
@test cat(2, t, t2) == StructArray{Pair}([3 1; 5 6], ["a" "a"; "b" "b"]) == hcat(t, t2)
31+
@test cat(t, t2; dims=2) == StructArray{Pair}([3 1; 5 6], ["a" "a"; "b" "b"]) == hcat(t, t2)
3232
@test hcat(t, t2) isa StructArray
3333
end
34+
35+
f_infer() = StructArray{ComplexF64}(rand(2,2), rand(2,2))
36+
@testset "inferrability" begin
37+
@inferred f_infer()
38+
end

0 commit comments

Comments
 (0)