diff options
author | Clyybber <darkmine956@gmail.com> | 2020-08-27 15:50:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-27 15:50:59 +0200 |
commit | fb58066b61b14f4a1d6cdb0f4a8f0a9ea4174d82 (patch) | |
tree | c6e573d9ac221c786ac9e0ca2cf0f186d87a6bbe /doc | |
parent | d11933ad998fb0a3eb51bbefbaa53e583aaa3ac1 (diff) | |
download | Nim-fb58066b61b14f4a1d6cdb0f4a8f0a9ea4174d82.tar.gz |
Fix #5691 (#15158)
* Fix #5691 * Cleanup and thoughts * Use scope approach * Seperate defined/declared/declaredInScope magics * Fix declaredInScope * Update spec accordingly
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 |