public protocol P { func hello() } public struct Empty : P { public func hello() { print("Hello from Empty") } } public struct Tuple: P { public init(_ tuple: T) {} public func hello() { print("Hello from Tuple") } } @available(macOS 10.15, *) struct Named : P { public func hello() { print("Hello from Named") } } @resultBuilder public struct Example { public static func buildOptional(_ v: T?) -> some P { if #available(macOS 100.0.1, *) { let result = v! result.hello() return result } else { let result = Empty() result.hello() return result } } public static func buildLimitedAvailability(_ component: T) -> some P { component } public static func buildBlock(_ components: T) -> T { return components } public static func buildBlock(_ v1: T1, _ v2: T2) -> Tuple<(T1, T2)> { return Tuple((v1, v2)) } } public func test() -> some P { if #available(macOS 100.0.1, *) { return Tuple<(Int, Int)>((0, 0)) } return Empty() } public func testUnavailable() -> some P { if #unavailable(macOS 100.0.1) { return Tuple<(Int, Int)>((0, 1)) } return Empty() } public func test_return_from_conditional() -> some P { if #available(macOS 10.15, *) { return Named() } return Tuple<(String, Int)>(("", 0)) } // This used to crash during serialization because // @available negates availability condition. @available(macOS, unavailable) public func testUnusable() -> some P { if #available(iOS 50, *) { return Named() } return Tuple<(String, Int)>(("", 0)) }