Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexing problem with generated LazyJSON.String object #14

Open
lwabeke opened this issue Dec 18, 2019 · 0 comments
Open

Indexing problem with generated LazyJSON.String object #14

lwabeke opened this issue Dec 18, 2019 · 0 comments

Comments

@lwabeke
Copy link
Contributor

lwabeke commented Dec 18, 2019

Hi

I was trying to see how compatible LazyJSON would be with my Unmarshal.jl package.
While trying to get it to work, I believe I found a few problems in the Unmarshal package, that is being addressed, but I also found some problems with LazyJSON.

getindex works with a string, but not with a LazyJSON.String{String}.

Here is a minimum working example:

julia> using JSON, LazyJSON

julia> d = Dict("2" => "Test2","1" => "Test1")
Dict{String,String} with 2 entries:
  "1" => "Test1"
  "2" => "Test2"

julia> jl = LazyJSON.parse(JSON.json(d))
LazyJSON.Object{Nothing,String} with 2 entries:
  "1" => "Test1"
  "2" => "Test2"

julia> jl["1"]
"Test1"

julia> k = collect(keys(jl))[1]
"1"

julia> typeof(k)
LazyJSON.String{String}

julia> jl[k]
ERROR: MethodError: no method matching pointer(::LazyJSON.String{String})
Closest candidates are:
  pointer(::String) at strings/string.jl:81
  pointer(::String, ::Integer) at strings/string.jl:82
  pointer(::SubString{String}) at strings/substring.jl:109
  ...
Stacktrace:
 [1] get_ic(::LazyJSON.Object{Nothing,String}, ::LazyJSON.String{String}, ::Tuple{Int64,UInt8}, ::Int64) at /Users/lwabeke/.julia/packages/LazyJSON/EmafJ/src/LazyJSON.jl:343
 [2] get_ic at /Users/lwabeke/.julia/packages/LazyJSON/EmafJ/src/LazyJSON.jl:327 [inlined]
 [3] _get at /Users/lwabeke/.julia/packages/LazyJSON/EmafJ/src/AbstractDict.jl:19 [inlined]
 [4] get at /Users/lwabeke/.julia/packages/LazyJSON/EmafJ/src/AbstractDict.jl:17 [inlined]
 [5] getindex(::LazyJSON.Object{Nothing,String}, ::LazyJSON.String{String}) at /Users/lwabeke/.julia/packages/LazyJSON/EmafJ/src/AbstractDict.jl:10
 [6] top-level scope at REPL[9]:1

julia> for iter keys(jl)
ERROR: syntax: invalid iteration specification
Stacktrace:
 [1] top-level scope at REPL[9]:0

julia> for iter in keys(jl)
         @show jl[iter]
         end
ERROR: MethodError: no method matching pointer(::LazyJSON.String{String})
Closest candidates are:
  pointer(::String) at strings/string.jl:81
  pointer(::String, ::Integer) at strings/string.jl:82
  pointer(::SubString{String}) at strings/substring.jl:109
  ...
Stacktrace:
 [1] get_ic(::LazyJSON.Object{Nothing,String}, ::LazyJSON.String{String}, ::Tuple{Int64,UInt8}, ::Int64) at /Users/lwabeke/.julia/packages/LazyJSON/EmafJ/src/LazyJSON.jl:343
 [2] get_ic at /Users/lwabeke/.julia/packages/LazyJSON/EmafJ/src/LazyJSON.jl:327 [inlined]
 [3] _get at /Users/lwabeke/.julia/packages/LazyJSON/EmafJ/src/AbstractDict.jl:19 [inlined]
 [4] get at /Users/lwabeke/.julia/packages/LazyJSON/EmafJ/src/AbstractDict.jl:17 [inlined]
 [5] getindex(::LazyJSON.Object{Nothing,String}, ::LazyJSON.String{String}) at /Users/lwabeke/.julia/packages/LazyJSON/EmafJ/src/AbstractDict.jl:10
 [6] macro expansion at ./show.jl:562 [inlined]
 [7] top-level scope at ./REPL[11]:2

I will try looking into a PR, but my first attempt at providing a method for Base.pointer(::LazyJSON.String{String}), resulted in a Julia segfault. Logging it here, in case someone else is quicker or I get distracted before being able to look at the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant