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

Pushing used suppresses the XDeclaredButNotUsed hint for some identifiers, but not others #22939

Closed
ee7 opened this issue Nov 14, 2023 · 2 comments · Fixed by #22944
Closed
Assignees
Labels

Comments

@ee7
Copy link
Contributor

ee7 commented Nov 14, 2023

Example

{.push used.}
const a = 42
proc b = echo "hi"
{.pop.}

Current behavior

The compiler outputs an XDeclaredButNotUsed hint for a (but not b):

/tmp/used.nim(2, 7) Hint: 'a' is declared but not used [XDeclaredButNotUsed]

Expected behavior

No such hint for a or b.

Nim Version

Nim 2.0.0 and devel (57ffeaf).

Additional Information

The below works as expected, to suppress both hints:

const a {.used.} = 42
proc b {.used.} = echo "hi"

Issue #4044 was closed 5 years ago, citing the above workaround for

{.push hint[XDeclaredButNotUsed]: off.}
const a = 42
proc b = echo "hi"
{.pop.}

which still produces the XDeclaredButNotUsed hint for both a and b.

The issue in the example was reported in the #main channel.

@ringabout
Copy link
Member

ringabout commented Nov 15, 2023

It's a subtle bug. I discovered it yesterday in #22913.

{.push used.}
let a {.deprecated.} = 42
proc b = echo "hi"
{.pop.}

Somehow for var/let/const sections, it needs a pre-existing pragma to make push in effect. Let me investigate it later.

@ringabout ringabout self-assigned this Nov 15, 2023
@ringabout
Copy link
Member

Yeah, the reason is that implicitPragmas is not applied to Identifiers withouu pragmas.

ringabout added a commit that referenced this issue Nov 15, 2023
Araq pushed a commit that referenced this issue Nov 19, 2023
#22944)

…var/let symbols


fixes #22939
fixes #16890

Besides, it was applied to let/const/var with pragmas, now it is
universally applied.

```nim
{.push exportc.}
proc foo =
  let bar = 12
  echo bar
{.pop.}
```

For example, the `bar` variable will be affected by `exportc`.
narimiran pushed a commit that referenced this issue Apr 26, 2024
#22944)

…var/let symbols

fixes #22939
fixes #16890

Besides, it was applied to let/const/var with pragmas, now it is
universally applied.

```nim
{.push exportc.}
proc foo =
  let bar = 12
  echo bar
{.pop.}
```

For example, the `bar` variable will be affected by `exportc`.

(cherry picked from commit cecaf9c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants