From b2f51e29504160da7bb6ee98af464c21a9a96efd Mon Sep 17 00:00:00 2001 From: Gampol T Date: Thu, 22 Oct 2020 10:40:45 +0700 Subject: [PATCH] Fix #13609 (#15567) * add documentation that discardable pragma cannot use on template * Update doc/manual.rst Co-authored-by: Euan * Update doc/manual.rst Co-authored-by: Euan Co-authored-by: Euan --- doc/manual.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doc/manual.rst b/doc/manual.rst index ddee5cabe5..ca53999acf 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -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