Files
swift-mirror/test/expr/closure/inference.swift
Dmitri Hrybenko 3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00

39 lines
948 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}}