Skip to content

Commit 7ed00f3

Browse files
authored
Merge pull request #17 from Roboneet/glitchfix
handle Tuple{} and Tuple
2 parents 0fb8791 + 2364647 commit 7ed00f3

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/anonymous.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,5 @@ function lower_anon(T::DataType)
9393
end
9494

9595
tags[:jl_anonymous] = function (d)
96-
constructtype(d[:typename].wrapper, d[:params]...)
96+
constructtype(d[:typename].wrapper, d[:params])
9797
end

src/extensions.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ function lower(v::DataType)
4242
:params => [v.parameters...])
4343
end
4444

45-
constructtype(T) = T
46-
constructtype(T, Ts...) = T{Ts...}
45+
constructtype(T, Ts) = (length(Ts) == 0) ? T : T{Ts...}
46+
constructtype(T::Type{Tuple}, Ts) = T{Ts...}
4747

48-
tags[:datatype] = d -> constructtype(resolve(d[:name]), d[:params]...)
48+
tags[:datatype] = d -> constructtype(resolve(d[:name]), d[:params])
4949

5050
lower(v::UnionAll) =
5151
BSONDict(:tag => "unionall",

src/write.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ismutable(T) = !isbitstype(T)
4747
ismutable(::Type{String}) = false
4848

4949
typeof_(x) = typeof(x)
50-
typeof_(T::Type) = Type{T}
50+
typeof_(T::DataType) = T
5151

5252
function _lower_recursive(x, cache, refs)
5353
_lower(x) = applychildren!(x -> _lower_recursive(x, cache, refs), lower(x)::Primitive)

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ mutable struct Foo
77
x
88
end
99

10+
struct T{A}
11+
x::A
12+
end
13+
1014
@testset "BSON" begin
1115

1216
@testset "Primitive Types" begin
@@ -16,6 +20,7 @@ end
1620
@test roundtrip_equal(UInt8[1,2,3])
1721
@test roundtrip_equal("b")
1822
@test roundtrip_equal([1,"b"])
23+
@test roundtrip_equal(Tuple)
1924
end
2025

2126
@testset "Complex Types" begin
@@ -29,6 +34,7 @@ end
2934
@test roundtrip_equal(Array{Real}(rand(2,3)))
3035
@test roundtrip_equal(1+2im)
3136
@test roundtrip_equal(Dict("a"=>1))
37+
@test roundtrip_equal(T(()))
3238
end
3339

3440
@testset "Circular References" begin

0 commit comments

Comments
 (0)