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

In for loop _ is accessible #15972

Closed
beef331 opened this issue Nov 15, 2020 · 6 comments
Closed

In for loop _ is accessible #15972

beef331 opened this issue Nov 15, 2020 · 6 comments
Labels
Invalid Code Acceptance Everything related to compiler not complaining about invalid code

Comments

@beef331
Copy link
Collaborator

beef331 commented Nov 15, 2020

Unlike pretty much anywhere else _ is accessible as a single parameter in a for loop.

Example

for _ in ["a"]:
  echo _

Current Output

a

Expected Output

Error: undeclared identifier: '_'

Tested on pretty much all Nim versions.

@disruptek
Copy link
Contributor

Feature.

@timotheecour
Copy link
Member

Feature.

agreed; but should be documented (maybe it is, haven't found it)

@timotheecour timotheecour added Documentation Content Related to documentation content (not generation). Easy labels Nov 15, 2020
@beef331
Copy link
Collaborator Author

beef331 commented Nov 15, 2020

@timotheecour why is this a feature, does it not defeat the purpose of _ being an unused value, which is consistent for for _, _ ..., tuple unpacking, and variable declaration?

@timotheecour
Copy link
Member

timotheecour commented Nov 15, 2020

my bad, i misread accessible as inaccessible.
you're right, this should give Error: undeclared identifier: '_' in top post.

when true:
  let (_, a, _) = (1,2,3)
  echo _ # Error: undeclared identifier: '_'
when true:
  let _ = 1
  echo _ # Error: undeclared identifier: '_'

@timotheecour timotheecour added Invalid Code Acceptance Everything related to compiler not complaining about invalid code and removed Documentation Content Related to documentation content (not generation). Easy labels Nov 15, 2020
@beef331
Copy link
Collaborator Author

beef331 commented Nov 15, 2020

Ah, thanks. Thought I was losing my mind after both you and disruptek said it's a feature.

ringabout added a commit to ringabout/Nim that referenced this issue Nov 16, 2020
@ringabout
Copy link
Member

ringabout commented Nov 16, 2020

How about this?

block _:
  echo "123"
  break _

I would expect this to error too.

Error: undeclared identifier: '_'

narimiran pushed a commit that referenced this issue Nov 18, 2020
* fix #15972

* add testcase

* more

(cherry picked from commit 0869d2a)
mildred pushed a commit to mildred/Nim that referenced this issue Jan 11, 2021
ardek66 pushed a commit to ardek66/Nim that referenced this issue Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Invalid Code Acceptance Everything related to compiler not complaining about invalid code
Projects
None yet
Development

No branches or pull requests

4 participants