You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should emit a warning (mark it with .warnUntilSwiftVersion(6)) for situations where the semantics will change in Swift 6:
When it will become an error (due to the scoping rules being fixed and there being no matching binding in scope after the change).
When it will start referring to a different value (e.g. due to shadowing, it refers to some binding now but will refer to a different binding after the change).
Along with these test cases, we should probably also have a negative test to make sure this warning isn't emitted when the binding won't change under the new rules.
The text was updated successfully, but these errors were encountered:
We shouldn't warn here. This was an error before Swift 5.2 because it's a soundness hole. Slava has cleaned the semantics up so that this errors properly in this case and in many others, which closes the regression here.
```
<stdin>:2:19: error: use of local variable 'a' before its declaration
defer { print(a) } // OK
^
<stdin>:3:9: note: 'a' declared here
let a = 0
^
```
Additional Detail from JIRA
md5: d23188547e5854b410cbffd95f343a9b
Issue Description:
Reported originally here: https://forums.swift.org/t/defer-can-take-variables-declared-after-itself-bug-or-feature/50821
We should emit a warning (mark it with
.warnUntilSwiftVersion(6)
) for situations where the semantics will change in Swift 6:When it will become an error (due to the scoping rules being fixed and there being no matching binding in scope after the change).
When it will start referring to a different value (e.g. due to shadowing, it refers to some binding now but will refer to a different binding after the change).
Along with these test cases, we should probably also have a negative test to make sure this warning isn't emitted when the binding won't change under the new rules.
The text was updated successfully, but these errors were encountered: