swiftlang/swift

[SR-3550] Compound name syntax for functions with no params

Open

#46,138 opened on 2017年1月5日

GitHub で見る
 (11 comments) (0 reactions) (0 assignees)Swift (69,989 stars) (10,719 forks)batch import
compilerdeclaration namesgood first issueswift evolution proposal needed

説明

Previous ID SR-3550
Radar None
Original Reporter @jtbandes
Type Improvement
Votes 0
Component/s Compiler
Labels Improvement, StarterProposal
Assignee None
Priority Medium

md5: 9e54c0bcc3910a9a4c3dc549a118933b

relates to:

  • SR-1408 NSArray indexesOfObjectsPassingTest cannot be called in Swift 3

Issue Description:

The "compound name" of a function can be used to resolve ambiguities with argument labels, e.g. foo(x:) or foo(_:). However, there's no such shortcut to specify an overload that has no arguments. A workaround is to use its type with as:

import Foundation
class C: NSObject {
    func foo() {}
    func foo(x: Int) {}
}

#selector(C.foo)  // error: ambiguous use of 'foo'
#selector(C.foo(x:))  // resolve ambiguity with compound name
#selector(C.foo as (C) -> () -> ())  // resolve ambiguity by specifying type

But it'd be nice to have some way of doing this without specifying the type. Perhaps foo(_) (for symmetry with foo(_:))?

コントリビューターガイド