The template is substituting both sides of the field initialization because you 
use the same parameter names as field names. This is the expanded expression:

`DualBinaryExpr[AddOp, L, R](x: x, y: y)`

You just have to rename the params (and give it a return type, but a separate 
issue).
    
    
    template `+`[L, R](lhs: L, rhs: R) =
      DualBinaryExpr[AddOp, L, R](l: lhs, r: rhs)
    
    
    Run

This allows for code like:
    
    
    type
      Foo = object
        a, b: int
    template consructWith(field: untyped, val: untyped): Foo =
      Foo(field: val)
    echo consructWith(a, 1)
    
    
    Run

Reply via email to