From e884367276ec18bced20c1492980817f54cb4134 Mon Sep 17 00:00:00 2001 From: Simon Leeb <52261246+sliemeobn@users.noreply.github.com> Date: Sun, 8 Dec 2024 13:36:39 +0100 Subject: [PATCH] better swift 6 compiler conditionals (#61) --- Sources/Elementary/ServerSupport/SendOnceBox.swift | 2 +- .../Elementary/ServerSupport/SendableAnyHTMLBox.swift | 6 +++--- Tests/ElementaryTests/SendableAnyHTMLBox.swift | 9 ++++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Sources/Elementary/ServerSupport/SendOnceBox.swift b/Sources/Elementary/ServerSupport/SendOnceBox.swift index 0151570..8bae568 100644 --- a/Sources/Elementary/ServerSupport/SendOnceBox.swift +++ b/Sources/Elementary/ServerSupport/SendOnceBox.swift @@ -1,4 +1,4 @@ -#if swift(>=6.0) && !hasFeature(Embedded) +#if compiler(>=6.0) && !hasFeature(Embedded) import Synchronization @available(macOS 15.0, *) diff --git a/Sources/Elementary/ServerSupport/SendableAnyHTMLBox.swift b/Sources/Elementary/ServerSupport/SendableAnyHTMLBox.swift index 4666a0e..3106581 100644 --- a/Sources/Elementary/ServerSupport/SendableAnyHTMLBox.swift +++ b/Sources/Elementary/ServerSupport/SendableAnyHTMLBox.swift @@ -8,7 +8,7 @@ public struct _SendableAnyHTMLBox: Sendable { enum Storage { case sendable(any HTML & Sendable) - #if swift(>=6.0) + #if compiler(>=6.0) // NOTE: protocol can be removed when macOS 15 is the minimum case sendOnceBox(any SendOnceBoxing) #endif @@ -18,14 +18,14 @@ public struct _SendableAnyHTMLBox: Sendable { storage = .sendable(html) } - #if swift(>=6.0) + #if compiler(>=6.0) @available(macOS 15, *) public init(_ html: sending any HTML) { storage = .sendOnceBox(SendOnceBox(html)) } #endif - #if swift(>=6.0) + #if compiler(>=6.0) public consuming func tryTake() -> sending (any HTML)? { switch storage { case let .sendable(html): diff --git a/Tests/ElementaryTests/SendableAnyHTMLBox.swift b/Tests/ElementaryTests/SendableAnyHTMLBox.swift index 191ee75..8da1944 100644 --- a/Tests/ElementaryTests/SendableAnyHTMLBox.swift +++ b/Tests/ElementaryTests/SendableAnyHTMLBox.swift @@ -1,7 +1,6 @@ import Elementary import XCTest -@available(macOS 15.0, *) final class SendOnceHTMLValueTests: XCTestCase { func testHoldsSendableValue() { let html = div { "Hello, World!" } @@ -10,8 +9,12 @@ final class SendOnceHTMLValueTests: XCTestCase { XCTAssertNotNil(box.tryTake()) } - #if swift(>=6.0) - func testHoldsNonSendable() { + #if compiler(>=6.0) + func testHoldsNonSendable() throws { + guard #available(macOS 15.0, *) else { + throw XCTSkip("Requires macOS 15.0") + } + let html = MyComponent() let box = _SendableAnyHTMLBox(html) XCTAssertNotNil(box.tryTake())