Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of _ (as var placeholder) inside a template causes XDeclaredButNotUsed hints #12094

Closed
kaushalmodi opened this issue Aug 30, 2019 · 1 comment · Fixed by #20635
Closed

Comments

@kaushalmodi
Copy link
Contributor

kaushalmodi commented Aug 30, 2019

It is typical to do something like (dirName, baseName, _) = splitFile("/a/b") where you do not care about that 3rd element of the tuple.

When that is used outside a template, as expected, the XDeclaredButNotUsed hint is not printed, good.

But when the same code is used inside a template, I get messages like:

Hint: '_`gensym722021' is declared but not used [XDeclaredButNotUsed]
CC: t.nim

Example

import os

template foo() =
  let
    (dirName, baseName, _) = splitFile("/a/b")
  echo dirName
  echo baseName
  echo "The _ causes the XDeclaredButNotUsed hint to appear when this code is in a template"

foo()

let
  (dirName2, baseName2, _) = splitFile("/a/b")
echo dirName2
echo baseName2
echo "When that _ is outside a template, it does not cause that Hint (which should be the case when inside a template too)"

Current Output

/home/kmodi/sandbox/nim/bug_reports/declared_but_not_used/t.nim(5, 25) Hint: '_`gensym543021' is declared but not used [XDeclaredButNotUsed]
Hint:  [Link]
Hint: operation successful (68333 lines compiled; 0.642 sec total; 90.695MiB peakmem; Debug Build) [SuccessX]
Hint: /home/kmodi/sandbox/nim/bug_reports/declared_but_not_used/t  [Exec]
/a
b
The _ causes the XDeclaredButNotUsed hint to appear when this code is in a template
/a
b
When that _ is outside a template, it does not cause that Hint (which should be the case when inside a template too)

Expected Output

The same output, but that Hint should not appear.

Additional Information

$ nim -v
Nim Compiler Version 0.20.99 [Linux: amd64]
Compiled at 2019-08-28
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 42d2e68bca2d7fce65591ed7c4697ed1ecf86026
active boot switches: -d:release

Update (2021/06/10):

I re-confirm this issue on the latest devel:

Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-06-10
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 19918ceb2b099440cd3e43b6d7fff313de6a84a2
active boot switches: -d:release
kaushalmodi added a commit to kaushalmodi/nim_config that referenced this issue Aug 30, 2019
The "discard _" is a workaround to get around the
nim-lang/Nim#12094 issue on current Nim
devel.
bung87 added a commit to bung87/Nim that referenced this issue Oct 23, 2022
bung87 added a commit to bung87/Nim that referenced this issue Oct 24, 2022
Araq pushed a commit that referenced this issue Oct 25, 2022
#20635)

fix #12094 Use of _ (as var placeholder) inside a template causes XDeclaredButNotUsed
@kaushalmodi
Copy link
Contributor Author

Thank you for the fix @bung87 !

metagn added a commit to metagn/Nim that referenced this issue Oct 28, 2022
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
…uses XDe… (nim-lang#20635)

fix nim-lang#12094 Use of _ (as var placeholder) inside a template causes XDeclaredButNotUsed
narimiran pushed a commit that referenced this issue Apr 25, 2023
#20635)

fix #12094 Use of _ (as var placeholder) inside a template causes XDeclaredButNotUsed

(cherry picked from commit 4728c52)
narimiran pushed a commit that referenced this issue Apr 25, 2023
narimiran pushed a commit that referenced this issue Apr 25, 2023
#20635)

fix #12094 Use of _ (as var placeholder) inside a template causes XDeclaredButNotUsed

(cherry picked from commit 4728c52)
narimiran pushed a commit that referenced this issue Apr 25, 2023
narimiran pushed a commit that referenced this issue Apr 25, 2023
#20635)

fix #12094 Use of _ (as var placeholder) inside a template causes XDeclaredButNotUsed

(cherry picked from commit 4728c52)
narimiran pushed a commit that referenced this issue Apr 25, 2023
bung87 added a commit to bung87/Nim that referenced this issue Jul 29, 2023
…uses XDe… (nim-lang#20635)

fix nim-lang#12094 Use of _ (as var placeholder) inside a template causes XDeclaredButNotUsed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants