swiftlang/swift

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

Open

#46,138 建立於 2017年1月5日

在 GitHub 查看
 (11 留言) (0 反應) (0 負責人)Swift (69,989 star) (10,719 fork)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(_:))?

貢獻者指南