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

json.to macro cannot handle ambiguous types even in a full form (module.Type) #11057

Closed
syhpoon opened this issue Apr 18, 2019 · 0 comments

Comments

Projects
None yet
4 participants
@syhpoon
Copy link

commented Apr 18, 2019

When a file imports several modules with ambiguous types, json.to macro doesn't seem to be able to produce correct code for compiler to digest.

Example

main.nim:

import json
import req1, req2

let raw = parseJson("""{"a": "test"}""")
let obj = to(raw, req1.Test)

req1.nim:

type
   Test* = object
      a*: string

req2.nim:

type
   Test* = object
      a*: string

Current Outcome

nim c main.nim

main.nim(6, 13) template/generic instantiation from here
~/.choosenim/toolchains/nim-0.19.4/lib/pure/json.nim(1451, 33) Error: ambiguous identifier: 'Test' --use req1.Test or req2.Test

The workaround like:

type T = req1.Test
let obj = to(raw, T)

works, but it smells a bit hacky.

Expected Outcome

File successfully compiled

Additional Information

$ nim -v
Nim Compiler Version 0.19.4 [Linux: amd64]
Compiled at 2019-02-01
Copyright (c) 2006-2018 by Andreas Rumpf

git hash: b6d96cafc8bcad1f3d32f2910b25cd11a93f7751

Araq added a commit that referenced this issue May 28, 2019

@Araq Araq closed this in 9d8b4d6 May 28, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.