`$` not working on custom type when imported in other modules

2022-03-27 Thread ynfle
Very true

`$` not working on custom type when imported in other modules

2022-03-27 Thread huantian
Using include like that is usually not the best idea unless you’ve thought about and understood your actions

`$` not working on custom type when imported in other modules

2022-03-27 Thread ynfle
I solution (depending what's in the file) could be to `include` it

`$` not working on custom type when imported in other modules

2022-03-27 Thread z_____________
If we call `$` explicitly, we get a more illuminating error message: `Error: ambiguous call; both dollars.$(x: int64) [proc declared in /path/to/lib/system/dollars.nim(14, 6)] and lib.$(i: Int_b) [func declared in /path/to/lib.nim(3, 6)] match for: (Int_b)`

`$` not working on custom type when imported in other modules

2022-03-27 Thread Yardanico
Ah, right, it's not a big - if you want to have a custom `$`, you need to use `distinct int64` instead. The reason is that `int64` already has `$` defined for it, so they conflict. It works in the same file because the local `$` overrides the global one AFAIK.

`$` not working on custom type when imported in other modules

2022-03-27 Thread Yardanico
For anyone curious for the exact source code, this seems to reproduce the problem: # lib.nim type Int_b* = int64 func `$`*(i: Int_b): string = "somestring" Run # main.nim import lib var a: Int_b echo a

`$` not working on custom type when imported in other modules

2022-03-27 Thread solomonthewise
I defined a type called int_b = int64 and defined a specific print format for it using $. It works within the module its defined in however when I attempt to print a int_b in another module I get this error message. I made sure to add the * so it would import. I'm likely making a stupid mistake