From 4d7f5077b3e83bf27c4ba668f0005a197c40abac Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 11 Feb 2025 22:48:05 -0800 Subject: [PATCH] chore: enable upcoming feature `InferSendableFromCaptures` A massive number of concurrency warnings concern `KeyPath` and issues with its sendability. Rather than chase these down make use of SE-0418, "Inferring Sendable for Methods and KeyPath Literals". `swift-tools-version` is updated to 5.10, making the upcoming feature, `InferSendableFromCaptures` available. Once done, the compiler needs a little help assembling a correct `KeyPath` for `\EnvironmentValues.theme`. A hint that it should be a `WritableKeyPath` is enough to get it on track. --- Package.swift | 5 ++++- Sources/MarkdownUI/Utility/Deprecations.swift | 4 ++-- .../MarkdownUI/Views/Environment/Environment+Theme.swift | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Package.swift b/Package.swift index 5fb61bc9..fe894cf4 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.6 +// swift-tools-version:5.10 import PackageDescription @@ -29,6 +29,9 @@ let package = Package( .product(name: "cmark-gfm", package: "swift-cmark"), .product(name: "cmark-gfm-extensions", package: "swift-cmark"), .product(name: "NetworkImage", package: "NetworkImage"), + ], + swiftSettings: [ + .enableUpcomingFeature("InferSendableFromCaptures") ] ), .testTarget( diff --git a/Sources/MarkdownUI/Utility/Deprecations.swift b/Sources/MarkdownUI/Utility/Deprecations.swift index 7a60dffa..f94567a0 100644 --- a/Sources/MarkdownUI/Utility/Deprecations.swift +++ b/Sources/MarkdownUI/Utility/Deprecations.swift @@ -55,7 +55,7 @@ extension View { _ keyPath: WritableKeyPath>, @ViewBuilder body: @escaping (_ label: BlockConfiguration.Label) -> Body ) -> some View { - self.environment((\EnvironmentValues.theme).appending(path: keyPath), .init(body: body)) + self.environment((\EnvironmentValues.theme as WritableKeyPath).appending(path: keyPath), .init(body: body)) } @available( @@ -71,7 +71,7 @@ extension View { @ViewBuilder body: @escaping (_ label: BlockConfiguration.Label) -> Body ) -> some View { self.environment( - (\EnvironmentValues.theme).appending(path: keyPath), + (\EnvironmentValues.theme as WritableKeyPath).appending(path: keyPath), .init { configuration in body(.init(configuration.label)) } diff --git a/Sources/MarkdownUI/Views/Environment/Environment+Theme.swift b/Sources/MarkdownUI/Views/Environment/Environment+Theme.swift index 7fd986a3..d50353de 100644 --- a/Sources/MarkdownUI/Views/Environment/Environment+Theme.swift +++ b/Sources/MarkdownUI/Views/Environment/Environment+Theme.swift @@ -15,7 +15,7 @@ extension View { _ keyPath: WritableKeyPath, @TextStyleBuilder textStyle: () -> S ) -> some View { - self.environment((\EnvironmentValues.theme).appending(path: keyPath), textStyle()) + self.environment((\EnvironmentValues.theme as WritableKeyPath).appending(path: keyPath), textStyle()) } /// Replaces a specific block style on the current ``Theme`` with a block style initialized with the given body closure. @@ -26,7 +26,7 @@ extension View { _ keyPath: WritableKeyPath>, @ViewBuilder body: @escaping () -> Body ) -> some View { - self.environment((\EnvironmentValues.theme).appending(path: keyPath), .init(body: body)) + self.environment((\EnvironmentValues.theme as WritableKeyPath).appending(path: keyPath), .init(body: body)) } /// Replaces a specific block style on the current ``Theme`` with a block style initialized with the given body closure. @@ -37,7 +37,7 @@ extension View { _ keyPath: WritableKeyPath>, @ViewBuilder body: @escaping (_ configuration: Configuration) -> Body ) -> some View { - self.environment((\EnvironmentValues.theme).appending(path: keyPath), .init(body: body)) + self.environment((\EnvironmentValues.theme as WritableKeyPath).appending(path: keyPath), .init(body: body)) } /// Replaces the current ``Theme`` task list marker with the given list marker.