Ok, seems like I just did not test the cases that are not working ;)
I think it has nothing to do with the wrapped types or the template at all. It
is just the + operator that makes problems. And now things are getting really
strange:
import typetraits
template myadd[L,R](lhs: L, rhs: R): auto =
echo "lhs is " & $lhs.type.name
echo "rhs is " & $rhs.type.name
lhs # with this line uncommented and the next line commented, the
code compiles
#lhs + rhs # with this line uncommented and the previous line commented,
the second call to myadd gives an error
var r1 = myadd(2, 2.0) # => "lhs is int" and "rhs is float64" -> works with
lhs+rhs in myadd
var ai = 2
var bf = 2.0
var r2 = myadd(ai, bf) # => "lhs is int" and "rhs is float64" -> error with
lhs+rhs in myadd (type mismatch: got (int, float64))
So at runtime, myadd tells me for both calls that it gets int and float64.
However, if I uncomment the line "lhs+rhs" in myadd, then the compiler crashes
in the second call to myadd (ONLY the second). At this point, I think someone
with a little knowledge about how the compiler works should explain this
behavior...