swiftlang/swift

[SR-5984] Error message for accidentally calling function in #selector(foo()) could suggest removing parens

开放

#48,543 创建于 2017年9月26日

 (4 条评论) (0 个反应) (0 位负责人)Swift (10,719 个派生)batch import
bugcompilerdiagnostics qualitygood first issuetype checker

仓库指标

星标
 (69,989 个星标)
PR 合并指标
 (平均合并 8天 17小时) (30 天内合并 510 个 PR)

描述

Previous ID SR-5984
Radar rdar://problem/34640740
Original Reporter @huonw
Type Bug
Status In Progress
Resolution

Swift 4.0

Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, StarterBug, TypeChecker
Assignee None
Priority Medium

md5: 939952c8851f309540d6ce3aaa7d7c15

Issue Description:

import Foundation

class Foo {
    @objc func foo() {
        _ = #selector(foo())
    }
}

call-selector.swift:5:13: error: argument of '#selector' does not refer to an '@objc' method, property, or initializer
        _ = #selector(foo())
            ^         ~~~~~

This is close to the correct syntax (#selector(foo)) and the compiler could help guide the user to this. This probably comes up most often with selectors for methods with no arguments (https://bugs.swift.org/browse/SR-1016).

贡献者指南