Let's look at a minimal code sample which reproduces the compiler error:
    
    
    template foo*(sFoo: untyped) =
      type A = object
        str: string
      
      sFoo
    
    foo:
      echo A(str: "hello").str
    
    
    Run

Type definitions inside a template are by default invisible to code from the 
instantiation scope (or gensym ed, see the manual chapter @Hlaaftana linked). 
`sFoo` comes from the instantiation scope, thus the error, which can be avoided 
by giving `A` an `{.inject.}` pragma.

When the definition of `A` is included instead, the `include` is apparently 
resolved after template substitution: `A` is not defined in the template body, 
but immediatly inside the instantiating context.

Reply via email to