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-12952] Could #selector be smarter about types? #55398

Open
mattneub opened this issue Jun 7, 2020 · 0 comments
Open

[SR-12952] Could #selector be smarter about types? #55398

mattneub opened this issue Jun 7, 2020 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@mattneub
Copy link

mattneub commented Jun 7, 2020

Previous ID SR-12952
Radar None
Original Reporter @mattneub
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 2352c5ac78663f4f20e56db78137212a

Issue Description:

This compiles, but crashes (quite rightly) at runtime:

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        let yoho = Notification.Name(rawValue: "yoho")
        let center = NotificationCenter.default
        center.addObserver(self, selector: #selector(foo), 
            name: yoho, object: nil)
        center.post(name: yoho, object: self)
    }
    @objc func foo(_ bar: String) {
        print(bar)
    }
}

My question is: Why does it compile? The Objective-C docs are quite clear: the selector should refer to a method whose parameter is an NSNotification. Why can't Swift save us from ourselves here?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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

1 participant