mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
The rule changes are as follows: * All functions (introduced with the 'func' keyword) have argument labels for arguments beyond the first, by default. Methods are no longer special in this regard. * The presence of a default argument no longer implies an argument label. The actual changes to the parser and printer are fairly simple; the rest of the noise is updating the standard library, overlays, tests, etc. With the standard library, this change is intended to be API neutral: I've added/removed #'s and _'s as appropriate to keep the user interface the same. If we want to separately consider using argument labels for more free functions now that the defaults in the language have shifted, we can tackle that separately. Fixes rdar://problem/17218256. Swift SVN r27704
39 lines
950 B
Swift
39 lines
950 B
Swift
// RUN: %target-parse-verify-swift
|
|
|
|
func takeIntToInt(f: (Int) -> Int) { }
|
|
func takeIntIntToInt(f: (Int, Int) -> Int) { }
|
|
|
|
// Anonymous arguments with inference
|
|
func myMap<T, U>(array: [T], _ f: (T) -> U) -> [U] {}
|
|
|
|
func testMap(array: [Int]) {
|
|
var farray = myMap(array, { Float($0) })
|
|
var f : Float = farray[0]
|
|
var farray2 = myMap(array, { x in Float(x) })
|
|
farray = farray2
|
|
}
|
|
|
|
// Infer result type.
|
|
func testResultType() {
|
|
takeIntToInt({x in
|
|
return x + 1
|
|
})
|
|
|
|
takeIntIntToInt({x, y in
|
|
return 2 + 3
|
|
})
|
|
}
|
|
|
|
// Closures with unnamed parameters
|
|
func unnamed() {
|
|
takeIntToInt({_ in return 1})
|
|
takeIntIntToInt({_, _ in return 1})
|
|
}
|
|
|
|
// Regression tests.
|
|
|
|
var nestedClosuresWithBrokenInference = { f: Int in {} }
|
|
// expected-error@-1 {{unable to infer closure type in the current context}}
|
|
// expected-error@-2 {{consecutive statements on a line must be separated by ';'}}
|
|
// expected-error@-3 {{expected expression}}
|