* add documentation that discardable pragma cannot use on template

* Update doc/manual.rst

Co-authored-by: Euan <euantorano@users.noreply.github.com>

* Update doc/manual.rst

Co-authored-by: Euan <euantorano@users.noreply.github.com>

Co-authored-by: Euan <euantorano@users.noreply.github.com>
(cherry picked from commit b2f51e2950)
This commit is contained in:
Gampol T
2020-10-22 10:40:45 +07:00
committed by narimiran
parent eb04535b53
commit bc5c6c812b

View File

@@ -2592,6 +2592,17 @@ been declared with the `discardable`:idx: pragma:
p(3, 4) # now valid
however the discardable pragma does not work on templates as templates substitute the AST in place. For example:
.. code-block:: nim
{.push discardable .}
template example(): string = "https://nim-lang.org"
{.pop.}
example()
This template will resolve into "https://nim-lang.org" which is a string literal and since {.discardable.} doesn't apply to literals, the compiler will error.
An empty ``discard`` statement is often used as a null statement:
.. code-block:: nim