I would argue erroring at compile time instead of bothering with a runtime
exception is "less code". You don't even have to use a macro, you can just use
the error pragma. I don't know why I gave a macro.
template final_sort2(v: bool): typedesc = bool
template final_sort2(v: typed) =
{.error: "Incompatible type: " & $typeof(v).} # Error: Incompatible type:
string
echo final_sort2(true)
echo final_sort2("hi") # template/generic instantiation of `final_sort2`
from here
Run
I would say this is as good as anything in regards to line/column information
if you dont want to write a tiny macro, but it's your call