Weird import issue

2021-08-13 Thread alexeypetrushin
> Since you already called to_json with a string argument your later invocation > of it uses the previously created proc. Thanks, I see now, thanks. I couldn't imagine it could work this way :) > if you change proc to template your example will work as expected. Indeed, it works. Although I thi

Weird import issue

2021-08-12 Thread solo989
This is expected behavior. Your unrelated proc calls to_json with the exact same types as echo "v".to_json Run if you change proc to_json*[T](v: T): JsonNode = when compiles(v.to_json_hook): v.to_json_hook else: v.to_json_default Run

Weird import issue

2021-08-12 Thread alexeypetrushin
I finally distilled it into a short example, [play](https://play.nim-lang.org/#ix=3vM2) with [2min video demo](https://youtu.be/kBoSyi8CqEM) explaining where's the problem. Problem: comment out the code marked in comments, which is completely unrelated, and it would produce different results.

Weird import issue

2021-08-12 Thread solo989
They are not bugs. You just don't understand how generics work versus non generics. Araq was mistaken at first and corrected himself when he said, Please have a look at Unfortunately the first example isn't quite comple

Weird import issue

2021-08-12 Thread alexeypetrushin
> Your example isn't generic. Thanks, I tried that, it doesn't work. It's actually even stranger. Note in all the examples `proc text` is used and `proc image` isn't used at all, yet it will affect how the code behaves. **Case 1** remove unused `proc image` and it would work, even with non-gene

Weird import issue

2021-08-11 Thread solo989
Your example isn't generic. Replace this proc text*(page: var Page, text: string): void = page.page.add (text: text).to_json proc image*(page: var Page, data: JsonNode): void = page.page.add (image: data).to_json Run with this proc

Weird import issue

2021-08-11 Thread alexeypetrushin
> Please have a look at > Thank you! As far as I understand the example above should work then? Because `to_json` (defined in std/jsonutils) is a **generic** that uses overloaded **open symbol** `to_json_hook` (defined

Weird import issue

2021-08-11 Thread Araq
Please have a look at

Weird import issue

2021-08-10 Thread alexeypetrushin
> So there's no way for plot.nim to know about your json hook. Actually, no it doesn't make sense. The JSON conversion stuff defined in `std/json` I define json hook in other modules. And yet `std/json` somehow knows about those hooks. So why this case is different?

Weird import issue

2021-08-09 Thread alexeypetrushin
> So there's no way for plot.nim to know about your json hook. If I use different JSON settings, how can I publish the `plot.nim` library? Other people have different hooks.

Weird import issue

2021-08-09 Thread alexeypetrushin
[Issue](https://github.com/nim-lang/Nim/issues/18661) created.

Weird import issue

2021-08-09 Thread jyapayne
@alexeypetrushin, is this surprising behavior? I think it should be expected since you are not importing `json_helpers.nim` inside `plot.nim`, and that's where the conversion inside the text proc happens. So there's no way for `plot.nim` to know about your json hook. You can modify the import o

Weird import issue

2021-08-09 Thread Araq
Report it on github please.

Weird import issue

2021-08-07 Thread alexeypetrushin
I use custom JSON generation code, it's controlled by exporting `to_json_hook` proc. The issue is that it's not imported properly, behaving in a weird way. The code below should print `[{"text":"Some text"}]` but instead it prints `[{"isUnquoted":false,"kind":5,"fields":{"text":{"isUnquoted":fa