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-9070] Variable shadowing inconsistency with guard #51571

Closed
dduan opened this issue Oct 24, 2018 · 1 comment
Closed

[SR-9070] Variable shadowing inconsistency with guard #51571

dduan opened this issue Oct 24, 2018 · 1 comment
Labels
compiler The Swift compiler in itself improvement

Comments

@dduan
Copy link
Collaborator

dduan commented Oct 24, 2018

Previous ID SR-9070
Radar None
Original Reporter @dduan
Type Improvement
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement
Assignee None
Priority Medium

md5: 789f83147ce9df556416144efb03b152

duplicates:

  • SR-214 Swift 2: Guard let can shadow func param but not let-bound local constant

Issue Description:

In the following snippet, function f compiles but g won't. Intuitively, one would expect rules for shadowing an argument and a local variable to be the same.

g should compile.

@belkadan
Copy link
Contributor

I'm not sure I necessarily agree that shadowing should be the same between parameters and locals. After all, this is allowed:

func test() {
  let x = 1
  do {
    let x = "abc"
    print(x)
  }
  print(x)
}
test()

which suggests that scopes are delimited by braces.

@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
compiler The Swift compiler in itself improvement
Projects
None yet
Development

No branches or pull requests

2 participants