Re: Generic function resolution

2020-07-11 Thread kartiku
Thank you. I've posted an [issue](https://github.com/nim-lang/Nim/issues/14942)


Re: Generic function resolution

2020-07-07 Thread solo989
It may be a bug or an implementation detail.

Either way I would report the issue on github.


Re: Generic function resolution

2020-07-07 Thread solo989
It's not actually calling 


proc g[T](d: string)


Run

without B.

What it's doing is

instantiate g1 withB

instantiate g2 withB

instantiate g1 withC

instantiate g2 withC

call g1 withB

call g2 withC

It only comes up when you explicitly pass in generic parameters. All functions 
that match the generic parameters are instantiated.


Re: Generic function resolution

2020-07-06 Thread kartiku
I should have been more clear. I left out the case T = C there on purpose. I 
expected the call 


f[C]("SM", d)

Run

to call 


proc f[T](k: string, d: string)

Run

but it is calling 


proc f[T](d: string)

Run

instead. Not sure if this is a bug in the compiler or my understanding of how 
generic functions work when they are overloaded like this.


Re: Generic function resolution

2020-07-06 Thread hugogranstrom
I think that it may complain about the first g[T] proc. It only works in the 
case T = B but unless that's the case you never create the variable l. So 
either you have to indent the echo statement to be within the when statement or 
you add a else statement to the when statement to handle the case where T isn't 
B, and define the variable l there as well.

Writing this from my phone so can't really write the code but I hope you get 
the point. 


Re: Generic function resolution

2020-07-06 Thread Vindaar
The issue is that you only define l in g when it is called with type B. In the 
let sk line however you call f with type C, which calls g with the same type. 
Thus, the when branch isn't part of the g proc for that case. So l is never 
defined.

Is that clear?


Re: Generic function resolution

2020-07-06 Thread kartiku
Can someone take a quick look? Its possible I'm doing something silly.