You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All the templates printVar should call are already defined but p isn't bound so it can potentially use new templates/procs/etc defined in the future.
myFile.nim
import foreignFile
var x =0templatep(a : int) =
x += a
echo x
p(7)
printVar(5)
printVar(5.0)
printVar("5.0")
In this example you've inadvertently overwritten p from myFile when aProc is passed an int.
It will echo 12 instead of Number:5.
You only wanted to call your new p definition directly.
In this case the generic printVar proc should probably be three seperate printVar definitions instead of
procprintVar*[T:int|float|string](a : T)
but you never know what your going to get when importing other peoples code.
The text was updated successfully, but these errors were encountered:
Works as by the spec, p is overloaded and so is an "open sym choice". This is also not a regression afaict, or if it is, the compiler used to be wrong and now it's correct. Workaround:
procprintVar*[T:int|float|string](a : T) =bind p
p(a)
Imagine you have two files foreignFile.nim and myFile.nim.
foreignFile.nim
All the templates printVar should call are already defined but p isn't bound so it can potentially use new templates/procs/etc defined in the future.
myFile.nim
In this example you've inadvertently overwritten p from myFile when aProc is passed an int.
It will echo 12 instead of Number:5.
You only wanted to call your new p definition directly.
In this case the generic printVar proc should probably be three seperate printVar definitions instead of
but you never know what your going to get when importing other peoples code.
The text was updated successfully, but these errors were encountered: