Skip to content

Commit

Permalink
Fix compiler error and warning introduced in Swift 5.6 (#80)
Browse files Browse the repository at this point in the history
- 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`.
  • Loading branch information
JohnSundell authored Mar 15, 2022
1 parent c27f685 commit b358860
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Sources/Plot/API/EnvironmentKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ 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<T>(identifier: StaticString) where Value == T? {
self.init(identifier: identifier, defaultValue: nil)
}

/// Initialize a key with an inferred identifier. The key's identifier will
/// 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<T>(autoIdentifier: StaticString = #function) where Value == T? {
self.init(identifier: autoIdentifier, defaultValue: nil)
}
}
Expand Down
7 changes: 6 additions & 1 deletion Sources/Plot/API/HTMLAnchorTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ 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.
case parent = "_parent"
/// 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 }
}

0 comments on commit b358860

Please sign in to comment.