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

Error: local variable is not used, but in fact it is #832

Closed
wolfseifert opened this issue Nov 15, 2023 · 6 comments · Fixed by #887
Closed

Error: local variable is not used, but in fact it is #832

wolfseifert opened this issue Nov 15, 2023 · 6 comments · Fixed by #887
Labels
bug Something isn't working

Comments

@wolfseifert
Copy link

The transpiler emits "error: local variable is not used", but in fact it is used.

Compiling

main: () = {
  b := true;
  i := 0;
  while i < 3 && b next i++ {
    std::cout << i << std::endl;
  }
}

yields

whiles.cpp2(2,3): error: local variable b is not used; consider changing its name to '_' to make it explicitly anonymous, or removing it entirely if its side effects are not needed

This happens at least since git version 11f2dbb.

@wolfseifert wolfseifert added the bug Something isn't working label Nov 15, 2023
@gregmarr
Copy link
Contributor

This check was added in 243d03d

@JohelEGP
Copy link
Contributor

JohelEGP commented Nov 20, 2023

Same for the reproducer of #825.
I'm explicitly discarding them!
Even if I use them, I still get an error: https://cpp2.godbolt.org/z/ze48hqe7h.

@JohelEGP
Copy link
Contributor

The reproducer of #825 has 3 similar variants:

  _ = :(copy b) _ = b;        // Doesn't move.
  for args do (copy c) _ = c; // Doesn't move.
f: (copy x) _    = x; // Moves.

Only the parameter of the function expression is diagnosed.
The parameter of both the for body and the function are equally local.
It seems inconsistent to diagnose the first one but not the other two.

@JohelEGP
Copy link
Contributor

It also rejects this case, called out by the commit message.

        (copy count := 0)
        while !ret.emplace_back(get_argument(count)).empty() next count++ { }

@JohelEGP
Copy link
Contributor

This case is accepted if you don't use UFCS (https://cpp2.godbolt.org/z/jYr1cEqfd):

perfects: @struct type = {
  operator(): (this, copy consume) = {
    i:=0;
    // consume(i); // Works.
    i.consume();
  }
}
main: () = { }

@JohelEGP
Copy link
Contributor

Same for the reproducer of #825.
I'm explicitly discarding them!
Even if I use them, I still get an error: https://cpp2.godbolt.org/z/ze48hqe7h.

Removing copy and forward also makes them work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants