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-4536] Useless diagnostic unwrapping weak self in closure #47113

Closed
NachoSoto opened this issue Apr 7, 2017 · 5 comments
Closed

[SR-4536] Useless diagnostic unwrapping weak self in closure #47113

NachoSoto opened this issue Apr 7, 2017 · 5 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation

Comments

@NachoSoto
Copy link
Contributor

Previous ID SR-4536
Radar rdar://problem/31511959
Original Reporter @NachoSoto
Type Bug
Status Resolved
Resolution Done
Environment
  • Swift version 3.1 (swiftlang-802.0.48 clang-802.0.38)

  • Swift version 4.0 (swiftlang-900.0.59 clang-900.0.34.2)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI
Assignee @NachoSoto
Priority Medium

md5: e28f8bd1ca54953bce648738e911d723

Issue Description:

Code:

class C {
    func f() {
        let _: () -> Void = { [weak self] in
            guard let self = self else { return }
            print(self)
        }
    }
}

Expected result:

It works, just like this works:

class C {
    func f() {
        let a = NSObject()
        
        let _: () -> Void = { [weak a] in
            guard let a = a else { return }
            print(a)
        }
    }
}

Actual result:

3 useless diagnostics:

  • Cannot convert value of type 'C?' to expected argument type '_OptionalNilComparisonType'

  • Pattern matching in a condition requires the 'case' keyword

  • Expression implicitly coerced from 'C?' to Any

@jckarter
Copy link
Member

jckarter commented Apr 7, 2017

@swift-ci create

@belkadan
Copy link
Contributor

These are terrible diagnostics, but it's worth noting that "self" is a keyword, not a normal variable name. (There's been requests to add support for this syntax anyway, though.)

@NachoSoto
Copy link
Contributor Author

> These are terrible diagnostics, but it's worth noting that "self" is a keyword, not a normal variable name.

That seems like a language implementation detail 😛 it behaves as a variable in many situations. But I see what you're saying.

@NachoSoto
Copy link
Contributor Author

Still an issue in Swift 4.0

@xedin
Copy link
Member

xedin commented Feb 5, 2020

Tried first snippet with master/5.2 and it type-checks correctly now. I think support for weak self has been recently implemented in the compiler. Please verify using master and/or 5.2 snapshot.

@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 diagnostics QoI Bug: Diagnostics Quality of Implementation
Projects
None yet
Development

No branches or pull requests

4 participants