Files
swift-mirror/test/ModuleInterface/function_builders.swift
Harlan Haskins e23e77b6a5 Allow function builder attrs on vars without bodies in interfaces (#29165)
The check for whether or not we can use a function builder on a property
checked whether the attached getter had a body, which is not always true for
module interfaces. Just disable that part of the check when compiling a
module interface.

rdar://58535753
2020-01-13 14:41:01 -08:00

47 lines
1.6 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -typecheck -module-name FunctionBuilders -emit-module-interface-path %t/FunctionBuilders.swiftinterface %s
// RUN: %FileCheck %s < %t/FunctionBuilders.swiftinterface
// RUN: %target-swift-frontend -I %t -typecheck -verify %S/Inputs/function_builders_client.swift
// RUN: %target-swift-frontend -compile-module-from-interface %t/FunctionBuilders.swiftinterface -o %t/FunctionBuilders.swiftmodule
@_functionBuilder
public struct TupleBuilder {
public static func buildBlock<T1, T2>(_ t1: T1, _ t2: T2) -> (T1, T2) {
return (t1, t2)
}
public static func buildBlock<T1, T2, T3>(_ t1: T1, _ t2: T2, _ t3: T3)
-> (T1, T2, T3) {
return (t1, t2, t3)
}
public static func buildBlock<T1, T2, T3, T4>(_ t1: T1, _ t2: T2, _ t3: T3, _ t4: T4)
-> (T1, T2, T3, T4) {
return (t1, t2, t3, t4)
}
public static func buildBlock<T1, T2, T3, T4, T5>(
_ t1: T1, _ t2: T2, _ t3: T3, _ t4: T4, _ t5: T5
) -> (T1, T2, T3, T4, T5) {
return (t1, t2, t3, t4, t5)
}
public static func buildDo<T>(_ value: T) -> T { return value }
public static func buildIf<T>(_ value: T?) -> T? { return value }
}
// CHECK-LABEL: public func tuplify<T>(_ cond: Swift.Bool, @FunctionBuilders.TupleBuilder body: (Swift.Bool) -> T)
public func tuplify<T>(_ cond: Bool, @TupleBuilder body: (Bool) -> T) {
print(body(cond))
}
public struct UsesBuilderProperty {
// CHECK: @FunctionBuilders.TupleBuilder public var myVar: (Swift.String, Swift.String) {
// CHECK-NEXT: get
// CHECK-NEXT: }
@TupleBuilder public var myVar: (String, String) {
"hello"
"goodbye"
}
}