Open timotheecour opened 5 years ago
The problem here is that var T
parameter passing makes no sense for template
, template
can always mutate due to its inlining semantics. IMO var T
for parameters in templates should be deprecated.
You can still use var
as a discriminator in overloading. The template can do one thing if the location is mutable and another if it isn't
type checking for templates doesn't work the same as for procs, causing bugs
Example0
can anyone spot the bug in
swapEndian
?despite looking type safe, it isn't so:
If we used a proc instead of a template, the compiler would (correctly) complain:
Error: for a 'var' type a variable needs to be passed; but 'uint64(x.output)' is immutable
Example1
Current Output
there's a few bugs here:
$T
shows as9223372036854775807
in 1st example (int)$T
crashes compiler in 2nd example (float)a, b: T
should have same type T but their types are actually int and int32Example2
in this example the signature matching itself should fail. Contrary to previous example, the bug happens during signature matching, which should fail (ie, not implicit conversion possible bc of
var
), but doesn'toutput:
[EDIT]
related issues
Additional Information
Your Nim version (output of
nim -v
). latest devel f50e4500c257e3d57654f5230db75042da233d24Was it working in the previous Nim releases? no