1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
// RUN: %target-swift-frontend %s -emit-ir | %FileCheck %s
// REQUIRES: CPU=x86_64
//
// Type parameters
//
infix operator ~>
func ~> <Target, Args, Result> (
target: Target,
method: (Target) -> (Args) -> Result)
-> (Args) -> Result
{
return method(target)
}
protocol Runcible {
associatedtype Element
}
struct Mince {}
struct Spoon: Runcible {
typealias Element = Mince
}
func split<Seq: Runcible>(_ seq: Seq) -> ((Seq.Element) -> Bool) -> () {
return {(isSeparator: (Seq.Element) -> Bool) in
return ()
}
}
var seq = Spoon()
var x = seq ~> split
//
// Indirect return
//
// CHECK-LABEL: define internal swiftcc { ptr, ptr } @"$s21partial_apply_generic5split{{[_0-9a-zA-Z]*}}FTA"(ptr noalias nocapture %0, ptr swiftself %1)
// CHECK: tail call swiftcc { ptr, ptr } @"$s21partial_apply_generic5split{{[_0-9a-zA-Z]*}}F"(ptr noalias %0,
struct HugeStruct { var a, b, c, d: Int }
struct S {
func hugeStructReturn(_ h: HugeStruct) -> HugeStruct { return h }
}
let s = S()
var y = s.hugeStructReturn
// CHECK-LABEL: define internal swiftcc { i64, i64, i64, i64 } @"$s21partial_apply_genericAA10HugeStructVACcAA1SVcfu_A2Ccfu0_TA"(i64 %0, i64 %1, i64 %2, i64 %3, ptr swiftself %4)
// CHECK: entry:
// CHECK: call swiftcc { i64, i64, i64, i64 } @"$s21partial_apply_genericAA10HugeStructVACcAA1SVcfu_A2Ccfu0_"(i64 %0, i64 %1, i64 %2, i64 %3)
// CHECK: }
//
// Witness method
//
protocol Protein {
static func veganOrNothing() -> Protein?
static func paleoDiet() throws -> Protein
}
enum CarbOverdose : Error {
case Mild
case Severe
}
class Chicken : Protein {
static func veganOrNothing() -> Protein? {
return nil
}
static func paleoDiet() throws -> Protein {
throw CarbOverdose.Severe
}
}
func healthyLunch<T: Protein>(_ t: T) -> () -> Protein? {
return T.veganOrNothing
}
let f = healthyLunch(Chicken())
func dietaryFad<T: Protein>(_ t: T) -> () throws -> Protein {
return T.paleoDiet
}
let g = dietaryFad(Chicken())
do {
try g()
} catch {}
//
// Incorrect assertion regarding inout parameters in NecessaryBindings
//
func coyote<T, U>(_ t: T, _ u: U) {}
func hawk<A, B, C>(_: A, _ b: B, _ c: C) {
let fn: (Optional<(A) -> B>, @escaping (inout B, C) -> ()) -> () = coyote
}
|