Repository navigation
Conversation
…t from the unused check
Araq
reviewed
Dec 5, 2026
| @@ -0,0 +1,17 @@ | |||
| # A local that a for-loop plugin declares is exempt from the unused check, as | |||
Member
There was a problem hiding this comment.
But why? for x in withLocal(): noUseOf(x) is like any other code, flag the unused x.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3312.
A template expansion and a macro plugin expansion push their call site onto
templCallInfoswhile their output is semchecked, sosemPragmasmarks the locals they declare(used)(#3276, #3310).tryForLoopPluginre-semchecks the plugin output without doing so, so a local that a for-loop plugin declares and the loop body does not reference is reported as unused. Instd/parfor,for i in 0 ||< 100:with a body that does not readifails with'pforI' is declared but not used.src/nimony/sem.nim:tryForLoopPluginpushes theforloop's position ontotemplCallInfosaround thesemExprof the plugin output, as the macro plugin path does.tests/nimony/plugins/deps/mforloop.nim: awithLocalmode that declareslet pluginTmp = 1before the loop body.tests/nimony/plugins/tforloopplugin_local.nim:for x in withLocal()andfor _ in withLocal()inside procs, where the body does not use the loop variable.As with a template's
untypedbody, a local the user declares inside the loop body is semchecked as part of the expansion and is exempt as well:let unused = 1in a||<body is no longer reported, the same as in the body passed to atemplate once(body: untyped).Tested on macOS arm64 with Nim devel: the new test fails on master (
'pluginTmp' is declared but not used) and passes with this change; the||<loop from the issue (with||<in place of||) prints its result instead of the error;nim c -r tools/tester.nim(withHASTUR_SKIP=tests/boot) reports 1530 / 1530 tests successful.