I replaced some generic parameters in your code with untyped templates and then 
always new errors appeared in procs that were called from the proc that showed 
the error, so it seems you have somewere the real bug, but the compiler can't 
show you the correct place (I've seen this behaviour before when generics are 
used in code I have written). I couldnt find out the exact place because nim 
and nimsuggest got into endless loops at 100% cpu when replacing the second 
proc with untyped template.

The following shows that normally your generic type idea works (and I think 
it's a good idea how you have written your code):
    
    
    type GenericType[K, V] = object
      key: K
      value: V
    
    func values*[K,V,T](t1: GenericType[K,V], t2: GenericType[K,T]): tuple[v1: 
V, v2: T] =
      result = (t1.value, t2.value)
    
    when isMainModule:
      var t1: GenericType[string, int]
      var t2: GenericType[string, char]
      t1.key = "abc"
      t1.value = 1
      t2.key = "abc"
      t2.value = '1'
      
      var v = values(t1, t2)
      echo v.v1
      echo v.v2
    
    
    Run

So for now I can only suggest when you use generics test your procs as soon as 
possible, because generic procs are often checked very late by the compiler 
which means that some incorrect procs only error when they are actually called 
in the code :(

Reply via email to