From c6b2d197c04df567ab602f3c22b032fc77241ea7 Mon Sep 17 00:00:00 2001 From: Iceman Date: Tue, 17 Dec 2024 12:57:00 +0900 Subject: [PATCH 1/2] Add test pattern for swift 5 --- Tests/ServiceContextTests/ServiceContextTests.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/ServiceContextTests/ServiceContextTests.swift b/Tests/ServiceContextTests/ServiceContextTests.swift index 496c23c..476be07 100644 --- a/Tests/ServiceContextTests/ServiceContextTests.swift +++ b/Tests/ServiceContextTests/ServiceContextTests.swift @@ -94,6 +94,9 @@ final class ServiceContextTests: XCTestCase { ServiceContext.withValue(.topLevel) { value = 12 // should produce no warnings } + await ServiceContext.withValue(.topLevel) { () async in + value = 12 // should produce no warnings + } } } From c926b0728f6618a4fd04e9a394bbdc9537df7baf Mon Sep 17 00:00:00 2001 From: Iceman Date: Tue, 17 Dec 2024 12:57:44 +0900 Subject: [PATCH 2/2] Fix swift5 cannot avoid compiler warning --- Sources/ServiceContextModule/ServiceContext.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sources/ServiceContextModule/ServiceContext.swift b/Sources/ServiceContextModule/ServiceContext.swift index 8500b60..e7b44fb 100644 --- a/Sources/ServiceContextModule/ServiceContext.swift +++ b/Sources/ServiceContextModule/ServiceContext.swift @@ -257,14 +257,12 @@ extension ServiceContext { } @available(*, deprecated, message: "Use the method with the isolation parameter instead.") + // Deprecated trick to avoid executor hop here; 6.0 introduces the proper replacement: #isolation @_disfavoredOverload public static func withValue(_ value: ServiceContext?, operation: () async throws -> T) async rethrows -> T { try await ServiceContext.$current.withValue(value, operation: operation) } #else - // Deprecated trick to avoid executor hop here; 6.0 introduces the proper replacement: #isolation - @available(*, deprecated, message: "Prefer withValue(_:isolation:operation:)") - @_disfavoredOverload @_unsafeInheritExecutor public static func withValue(_ value: ServiceContext?, operation: () async throws -> T) async rethrows -> T { try await ServiceContext.$current.withValue(value, operation: operation)