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

[SR-2115] unused variable unreported by compiler #44723

Closed
swift-ci opened this issue Jul 19, 2016 · 12 comments
Closed

[SR-2115] unused variable unreported by compiler #44723

swift-ci opened this issue Jul 19, 2016 · 12 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-2115
Radar None
Original Reporter erica (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, StarterBug
Assignee KingOfBrian (JIRA)
Priority Medium

md5: 9c3041434c2dac44b9c1f658849c7920

Issue Description:

for i in sequence(first: 0, next: {
    print($0)
    let value = $0 + 5
    return value <= 100 ? value : nil
}) {}
@swift-ci
Copy link
Collaborator Author

Comment by erica sadun (JIRA)

The compiler should emit a warning / fixit for "i" as it is never used

@belkadan
Copy link
Contributor

I can't remember, but we might have done this deliberately because some people don't like having to write _ in their for-loops.

@swift-ci
Copy link
Collaborator Author

Comment by erica sadun (JIRA)

Even if deliberate, it still strikes me as wrong. Variable is never used.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Dec 5, 2016

Comment by emlai (JIRA)

This seems to have been fixed. I get "Immutable value 'i' was never used; consider replacing with '_' or removing it" for the above code in Swift 3.0.2 preview 1.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Dec 5, 2016

Comment by erica sadun (JIRA)

I don't see errors or warnings in Xcode 8.2 beta 2 or in Xcode 8.1

@belkadan
Copy link
Contributor

belkadan commented Dec 5, 2016

Ah, I see the warning if the loop is within a function body, but not at top-level in a script mode file.

@belkadan
Copy link
Contributor

belkadan commented Dec 5, 2016

(so it does make sense to treat it as a bug)

@belkadan
Copy link
Contributor

belkadan commented Dec 5, 2016

Tagging as StarterBug because it's probably just figuring out the conditions under which this warning is and is not emitted and then changing them.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Dec 5, 2016

Comment by erica sadun (JIRA)

When I moved the loop from the global scope of main.swift (maxOS, command line project) into a function, it warned.

Should warn at global scope too.

@swift-ci
Copy link
Collaborator Author

Comment by Brian (JIRA)

VarDeclUsageChecker was only running on AbstractFunctionDecl – I added a check to TopLevelCodeDecl too.

#6971

@swift-ci
Copy link
Collaborator Author

Comment by Brian (JIRA)

Take 2: #7023

@swift-ci
Copy link
Collaborator Author

swift-ci commented Feb 2, 2017

Comment by Brian (JIRA)

This behavior was fixed and should be available in Swift 4.0.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants