swiftlang/swift

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

Open

#46.138 geöffnet am 5. Jan. 2017

Auf GitHub ansehen
 (11 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Swift (10.719 Forks)batch import
compilerdeclaration namesgood first issueswift evolution proposal needed

Repository-Metriken

Stars
 (69.989 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 8T 17h) (510 gemergte PRs in 30 T)

Beschreibung

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(_:))?

Contributor Guide