* 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:
parent
e09c259bf3
commit
b2f51e2950
1 changed files with 11 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue