mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
41 lines
1.0 KiB
Swift
41 lines
1.0 KiB
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 _ : Float = farray[0]
|
|
let farray2 = myMap(array, { x in Float(x) })
|
|
farray = farray2
|
|
_ = farray
|
|
}
|
|
|
|
// 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 {{expression resolves to an unused function}}
|
|
// expected-error@-2 {{consecutive statements on a line must be separated by ';'}} {{44-44=;}}
|
|
// expected-error@-3 {{expected expression}}
|
|
// expected-error@-4 {{use of unresolved identifier 'f'}}
|