I pulled this example directly from the manual. The docs and I are both at 0.19.4.
template additive(typ: type) =
proc `+` *(x, y: typ): typ {.borrow.}
proc `-` *(x, y: typ): typ {.borrow.}
# unary operators:
proc `+` *(x: typ): typ {.borrow.}
proc `-` *(x: typ): typ {.borrow.}
template multiplicative(typ, base: type) =
proc `*` *(x: typ, y: base): typ {.borrow.}
proc `*` *(x: base, y: typ): typ {.borrow.}
proc `div` *(x: typ, y: base): typ {.borrow.}
proc `mod` *(x: typ, y: base): typ {.borrow.}
template comparable(typ: type) =
proc `<` * (x, y: typ): bool {.borrow.}
proc `<=` * (x, y: typ): bool {.borrow.}
proc `==` * (x, y: typ): bool {.borrow.}
template defineCurrency(typ, base: untyped) =
type
typ* = distinct base
additive(typ)
multiplicative(typ, base)
comparable(typ)
defineCurrency(Dollar, int)
defineCurrency(Euro, int)
When I run it, I get this:
hello.nim(27, 15) template/generic instantiation from here
hello.nim(24, 17) Error: type mismatch: got <type Dollar, type int>
but expected one of:
template multiplicative(typ, base: type)
first type mismatch at position: 2
required type: type
but expression 'int' is of type: type int
expression: multiplicative(Dollar, int)
What's up with that? Is there a typo in the example in the manual, or is there a bug in the compiler? I wanna file an issue on Github, but I don't know where...
For reference, some more discussion about this here: https://github.com/nim-lang/Nim/issues/11058
And quoting @Araq from my conversation with him directly:
it's 'type' for type sections, 'typeof' for typeof and 'typedesc' as the metatype for types
Many 👍s for this from me.