Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/JSON3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function Base.iterate(arr::Array{T}, (i, tapeidx)=(1, 3)) where {T}
i > length(arr) && return nothing
tape = gettape(arr)
@inbounds t = tape[tapeidx]
val = getvalue(T, getbuf(arr), tape, tapeidx, t)
val = getvalue(Any, getbuf(arr), tape, tapeidx, t)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is bad; this is how we can get fast, type-stable code when accessing elements of JSON3.Array{T}

tapeidx += gettapelen(T, t)
return val, (i + 1, tapeidx)
end
Expand All @@ -110,7 +110,7 @@ end
if regularstride(T)
tapeidx = 1 + 2 * i
@inbounds t = tape[tapeidx]
return getvalue(T, buf, tape, tapeidx, t)
return getvalue(Any, buf, tape, tapeidx, t)
else
tapeidx = 3
idx = 1
Expand Down
8 changes: 4 additions & 4 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ function promoteeltype(A, B)
return B
elseif (A | B) == A
return A
elseif A == INT && B == FLOAT
return A | B
elseif A == FLOAT && B == INT
return A | B
elseif A & INT == INT && B == FLOAT
return A & ~INT | FLOAT
elseif A & FLOAT == FLOAT && B == INT
return A
elseif A == NULL || B == NULL
return A | B
else
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,10 @@ txt = """
# https://github.com/quinnj/JSON3.jl/issues/8
@test eltype(JSON3.read("[1.2, 2.0]")) === Float64
@test eltype(JSON3.read("[1.2, 2.0, 3.3]")) === Float64
@test eltype(JSON3.read("[1, 2]")) == Int64
@test eltype(JSON3.read("[1, 2.3]")) == Float64
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case is problematic; the problem is that parsing already parsed 1 as an Int64, so we can't have the final eltype be Float64 or it will reinterpret the first element wrong (it will reinterpret the bits as Float64 when the bits are encoded as Int64).

@test eltype(JSON3.read("[1, null, 2]")) == Union{Nothing,Int64}
@test eltype(JSON3.read("[1, null, 2.3]")) == Union{Nothing,Float64}

# https://github.com/quinnj/JSON3.jl/issues/9
d = Dict(uuid1() => i for i in 1:3)
Expand Down