Typed vs untyped parameters

An untyped parameter means that symbol lookups and type resolution is not performed before the expression is passed to the template. This means that for example undeclared identifiers can be passed to the template:

  1. template declareInt(x: untyped) =
  2. var x: int
  3. declareInt(x) # valid
  4. x = 3
  1. template declareInt(x: typed) =
  2. var x: int
  3. declareInt(x) # invalid, because x has not been declared and so has no type

A template where every parameter is untyped is called an immediate template. For historical reasons templates can be explicitly annotated with an immediate pragma and then these templates do not take part in overloading resolution and the parameters’ types are ignored by the compiler. Explicit immediate templates are now deprecated.

Note: For historical reasons stmt was an alias for typed and expr was an alias for untyped, but they are removed.