* 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>
This commit is contained in:
Gampol T
2020-10-22 10:40:45 +07:00
committed by GitHub
parent e09c259bf3
commit b2f51e2950

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