Files
swift-mirror/test/Interpreter/functions.swift
Arnold Schwaighofer fb9696f427 IRGen: Fix mismatching sret attribute for indirect return values
We incorrectly lowered callsites when we had sil function return types
that involved both direct return types that we decide to lower
indirectly,  and indirect return types.

@convention(thin) () -> (@owned String, @owned String, @owned String, @out Any, @out Any)

(This should have been handled by the address lowering pass but isn't)

rdar://35874410
2017-12-19 18:58:53 -08:00

55 lines
975 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())
protocol Number {}
extension Int: Number {}
func foo() -> (String, String, String, Number, Number) {
return ("1", "2", "3", 42, 7)
}
// CHECK: ("1", "2", "3", 42, 7)
print(foo())