Files
swift-mirror/test/Interpreter/functions.swift
Chris Willmore 983a674e0c Make use of curried function declaration syntax an error.
<rdar://problem/23111018>
2016-01-20 21:57:38 -08:00

45 lines
774 B
Swift

// RUN: %target-run-simple-swift | FileCheck %s
// REQUIRES: executable_test
func double(x: Int) -> Int {
return x+x
}
func curriedSubtract(x: Int) -> (Int) -> Int {
return { y in x - y }
}
func twice(f: (Int) -> Int, _ x: Int) -> Int {
return f(f(x))
}
// CHECK: 4
print(double(2))
// CHECK: 8
print(double(4))
// CHECK: 12
print(curriedSubtract(16)(4))
// CHECK: 20
print(twice(double, 5))
// CHECK: 7
print(twice({ $0 + 1 }, 5))
// CHECK: 3
print(twice({ x in x - 1 }, 5))
// <rdar://problem/22044607>
class C {}
class D : C {}
func foo(a: Any, p2: Bool = true) { print("Wrong") }
func foo(c: C) { print("Right") }
func bar(a: Any..., p2: Bool = true) { print("Wrong") }
func bar(c: C) { print("Right") }
// CHECK: Right
foo(D())
// CHECK: Right
bar(D())