diff options
Diffstat (limited to 'doc')
-rw-r--r-- | doc/manual.rst | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/doc/manual.rst b/doc/manual.rst index 4d26421fe..b78e11b32 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -5019,23 +5019,16 @@ delayed until template instantiation time: :status: 1 template t(body: typed) = + proc p = echo "hey" block: body t: - var i = 1 - echo i + p() # fails with 'undeclared identifier: p' - t: - var i = 2 # fails with 'attempt to redeclare i' - echo i - -The above code fails with the mysterious error message that ``i`` has already -been declared. The reason for this is that the ``var i = ...`` bodies need to -be type-checked before they are passed to the ``body`` parameter and type -checking in Nim implies symbol lookups. For the symbol lookups to succeed -``i`` needs to be added to the current (i.e. outer) scope. After type checking -these additions to the symbol table are not rolled back (for better or worse). +The above code fails with the error message that ``p`` is not declared. +The reason for this is that the ``p()`` body is type-checked before getting +passed to the ``body`` parameter and type checking in Nim implies symbol lookups. The same code works with ``untyped`` as the passed body is not required to be type-checked: @@ -5043,16 +5036,12 @@ type-checked: :test: "nim c $1" template t(body: untyped) = + proc p = echo "hey" block: body t: - var i = 1 - echo i - - t: - var i = 2 # compiles - echo i + p() # compiles Varargs of untyped |