swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.25k stars 10.32k forks source link

[SR-9030] yet another misplaced "ambiguous reference" error message #51533

Open mattneub opened 5 years ago

mattneub commented 5 years ago
Previous ID SR-9030
Radar None
Original Reporter @mattneub
Type Improvement
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Improvement, DiagnosticsQoI | |Assignee | None | |Priority | Medium | md5: 7e8e1a5e1380eef1796eec2be27b68a0

Issue Description:

class C : NSObject, UITableViewDataSource {
    func tableView(_ tableView: UITableView, 
        numberOfRowsInSection section: Int) -> Int {
            return 1
    }
    func tableView(_ tableView: UITableView, 
        cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            return UITableViewCell()
    }
    func test() {
        _ = self.tableView.indexPathForSelectedRow
        // error: ambiguous reference 
        // to member 'tableView(_:numberOfRowsInSection:)'
    }
}

There's no ambiguous reference to anything. The problem, quite unambiguously, is that `self.tableView` is not a thing.

belkadan commented 5 years ago

self.tableView is a thing; in fact it's many things: all of the delegate functions. But the compiler should say that, and not just pick one of them and pretend it's what you typed.