mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-04 20:17:42 +00:00
* 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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user