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-8669] Guard can't access variable if it declares a variable shadowing it #51183

Closed
swift-ci opened this issue Aug 31, 2018 · 2 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-8669
Radar rdar://problem/75854765
Original Reporter montyoverzero (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

macOS 10.13.6, Xcode 9.4.1, Swift 4.1

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug
Assignee montyoverzero (JIRA)
Priority Medium

md5: 3b98c8084924683eb7cee7d4d9ddef56

Issue Description:

If you attempt to use a guard statement to declare a variable that shadows an existing variable, a compiler error prevents you from accessing the existing variable in the body of the guard.

func fooBar (foo: String?, bar: String?) -> Bool {    
  guard let foo = foo, let bar = bar else {        
    return foo == nil && bar == nil
    // "Variable declared in 'guard' condition is not usable in its body"
  }    
  return true
}
@weissi
Copy link
Member

weissi commented Mar 25, 2021

@swift-ci create

@xedin
Copy link
Member

xedin commented Mar 29, 2021

Looks like this has been fixed on main. I think by some recent changes to name lookup @slavapestov implemented. montyoverzero (JIRA User) Could you please use the latest main branch snapshot to verify and close?

@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
Projects
None yet
Development

No branches or pull requests

3 participants