Skip to content

Commit 25c6739

Browse files
authored
Fix ambiguity dispatch for Integer. Fixes https://github.com/JuliaDat… (#231)
* Fix ambiguity dispatch for Integer. Fixes JuliaData/StructTypes.jl#85 * bump Julia compat to 1.6
1 parent 8cc4467 commit 25c6739

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
version:
18-
- '1.0'
18+
- '1.6'
1919
- '1' # automatically expands to the latest stable 1.x release of Julia
2020
- 'nightly'
2121
os:

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
1313
[compat]
1414
Parsers = "0.3, 1, 2"
1515
StructTypes = "1.5"
16-
julia = "1"
16+
julia = "1.6"
1717

1818
[extras]
1919
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/structs.jl

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ read(::NumberType, buf, pos, len, b, S::Type{Union{Bool, T}}; kw...) where {T <:
6363
# without this, `Real` dispatches to the above definition
6464
read(::NumberType, buf, pos, len, b, ::Type{Real}; kw...) =
6565
read(NumberType(), buf, pos, len, b, Union{Float64, Int64}; kw...)
66+
read(::NumberType, buf, pos, len, b, ::Type{Integer}; kw...) =
67+
read(NumberType(), buf, pos, len, b, Int64; kw...)
6668

6769
@generated function read(::Struct, buf, pos, len, b, T::Union; kw...)
6870
U = first(T.parameters) # Extract Union from Type

test/runtests.jl

+14
Original file line numberDiff line numberDiff line change
@@ -1045,4 +1045,18 @@ x = System(duration=3600.0)
10451045
include("gentypes.jl")
10461046
include("stringnumber.jl")
10471047

1048+
# https://github.com/JuliaData/StructTypes.jl/issues/85
1049+
struct Struct1
1050+
iarr::Vector{Integer}
1051+
end
1052+
1053+
StructTypes.StructType(::Type{Struct1}) = StructTypes.Struct()
1054+
1055+
s1 = Struct1([1,2,3,4,5]);
1056+
iob = IOBuffer();
1057+
JSON3.write(iob, s1);
1058+
s1_json = String(take!(iob))
1059+
s2 = JSON3.read(s1_json, Struct1)
1060+
@test s1.iarr == s2.iarr
1061+
10481062
end # @testset "JSON3"

0 commit comments

Comments
 (0)