From b358860fe565eb53e98b1f5807eb5939c8124547 Mon Sep 17 00:00:00 2001 From: John Sundell Date: Tue, 15 Mar 2022 17:58:17 +0100 Subject: [PATCH] Fix compiler error and warning introduced in Swift 5.6 (#80) - Replace `HTMLAnchorTarget.self` with `.current` (while still maintaining backward compatibility with `.self` using a deprecated computed property). - Use per-`init` generic type constraints for optional `EnvironmentKey.Value` types rather than applying an extension-wide constraint using `ExpressibleByNilLiteral`. --- Sources/Plot/API/EnvironmentKey.swift | 6 +++--- Sources/Plot/API/HTMLAnchorTarget.swift | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Sources/Plot/API/EnvironmentKey.swift b/Sources/Plot/API/EnvironmentKey.swift index 10fda7b..e5eb081 100644 --- a/Sources/Plot/API/EnvironmentKey.swift +++ b/Sources/Plot/API/EnvironmentKey.swift @@ -39,11 +39,11 @@ public extension EnvironmentKey { } } -public extension EnvironmentKey where Value: ExpressibleByNilLiteral { +public extension EnvironmentKey { /// Initialize a key with an explicit identifier. /// - parameter identifier: The identifier that the key should have. Must /// be a static string that's defined using a compile time literal. - init(identifier: StaticString) { + init(identifier: StaticString) where Value == T? { self.init(identifier: identifier, defaultValue: nil) } @@ -51,7 +51,7 @@ public extension EnvironmentKey where Value: ExpressibleByNilLiteral { /// be computed based on the name of the property or function that created it. /// - parameter autoIdentifier: This parameter will be filled in by the /// compiler based on the name of the call site's enclosing function/property. - init(autoIdentifier: StaticString = #function) { + init(autoIdentifier: StaticString = #function) where Value == T? { self.init(identifier: autoIdentifier, defaultValue: nil) } } diff --git a/Sources/Plot/API/HTMLAnchorTarget.swift b/Sources/Plot/API/HTMLAnchorTarget.swift index 0eff6bd..ba7f890 100644 --- a/Sources/Plot/API/HTMLAnchorTarget.swift +++ b/Sources/Plot/API/HTMLAnchorTarget.swift @@ -10,7 +10,7 @@ import Foundation /// attribute, which specifies how its URL should be opened. public enum HTMLAnchorTarget: String { /// The URL should be opened in the current browser context (default). - case `self` = "self" + case current = "self" /// The URL should be opened in a new, blank tab or window. case blank = "_blank" /// The URL should be opened in any parent frame. @@ -18,3 +18,8 @@ public enum HTMLAnchorTarget: String { /// The URL should be opened in the topmost frame. case top = "_top" } + +extension HTMLAnchorTarget { + @available(*, deprecated, message: "Use .current instead") + static var `self`: Self { current } +}