Skip to content

Commit cbdcf98

Browse files
fix Dic bug
1 parent c9d7d34 commit cbdcf98

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

Manifest.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file is machine-generated - editing it directly is not advised
2+

src/BSON.jl

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,7 @@ export bson
55

66
using Core: SimpleVector, TypeName
77

8-
struct BSONDict <: AbstractDict{Symbol,Any}
9-
d::Dict{Symbol,Any}
10-
BSONDict(v...) = new(Dict{Symbol,Any}(v...))
11-
end
12-
# implement some of the needed Dict methods
13-
Base.length(bd::BSONDict) = length(bd.d)
14-
Base.isempty(bd::BSONDict) = length(bd.d)==0
15-
Base.setindex!(bd::BSONDict, v, k) = setindex!(bd.d, v, k)
16-
Base.getindex(bd::BSONDict, k) = getindex(bd.d, k)
17-
Base.iterate(bd::BSONDict) = iterate(bd.d)
18-
Base.iterate(bd::BSONDict, i) = iterate(bd.d, i)
19-
Base.get(bd::BSONDict, k, d) = get(bd.d, k, d)
20-
Base.delete!(bd::BSONDict, k) = delete!(bd.d, k)
21-
8+
const BSONDict = Dict{Symbol,Any}
229
const BSONArray = Vector{Any}
2310
const Primitive = Union{Nothing,Bool,Int32,Int64,Float64,String,Vector{UInt8},BSONDict,BSONArray}
2411

src/extensions.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
lower(x::Dict{Symbol}) = BSONDict(x)
2+
lower(x::BSONDict) = BSONDict(x)
23

34
# Basic Types
45

test.bson

-5.64 MB
Binary file not shown.

test/runtests.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
using BSON
22
using Test
33

4-
roundtrip_equal(x) = BSON.roundtrip(x) == x
4+
function roundtrip_equal(x)
5+
y = BSON.roundtrip(x)
6+
typeof(y) == typeof(x) && x == y
7+
end
8+
9+
# avoid hitting bug where
10+
# Dict{Symbol,T} -> Dict{Symbol,Any}
11+
function roundtrip_equal(x::Dict{Symbol})
12+
y = BSON.roundtrip(x)
13+
y isa Dict{Symbol} && y == x
14+
end
515

616
mutable struct Foo
717
x

0 commit comments

Comments
 (0)