Skip to content

resolve warning from recent Version constructor changes #3654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Commands/SwiftPackageCollectionsTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
let result = try tsc_await { collections.getPackageMetadata(reference, callback: $0) }

if let versionString = version {
guard let version = TSCUtility.Version(string: versionString), let result = result.package.versions.first(where: { $0.version == version }), let printedResult = printVersion(result) else {
guard let version = TSCUtility.Version(versionString), let result = result.package.versions.first(where: { $0.version == version }), let printedResult = printVersion(result) else {
throw CollectionsError.invalidVersionString(versionString)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Commands/SwiftPackageTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ extension SwiftPackageTool.Config {

extension SwiftPackageTool {
struct ResolveOptions: ParsableArguments {
@Option(help: "The version to resolve at", transform: { Version(string: $0) })
@Option(help: "The version to resolve at", transform: { Version($0) })
var version: Version?

@Option(help: "The branch to resolve at")
Expand Down
12 changes: 6 additions & 6 deletions Sources/PackageLoading/ManifestJSONParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -461,18 +461,18 @@ extension PackageDependency.SourceControl.Requirement {

case "range":
let lowerBoundString = try json.get(String.self, forKey: "lowerBound")
guard let lowerBound = Version(string: lowerBoundString) else {
guard let lowerBound = Version(lowerBoundString) else {
throw InternalError("invalid version \(lowerBoundString)")
}
let upperBoundString = try json.get(String.self, forKey: "upperBound")
guard let upperBound = Version(string: upperBoundString) else {
guard let upperBound = Version(upperBoundString) else {
throw InternalError("invalid version \(upperBoundString)")
}
self = .range(lowerBound ..< upperBound)

case "exact":
let versionString = try json.get(String.self, forKey: "identifier")
guard let version = Version(string: versionString) else {
guard let version = Version(versionString) else {
throw InternalError("invalid version \(versionString)")
}
self = .exact(version)
Expand All @@ -489,18 +489,18 @@ extension PackageDependency.Registry.Requirement {
switch type {
case "range":
let lowerBoundString = try json.get(String.self, forKey: "lowerBound")
guard let lowerBound = Version(string: lowerBoundString) else {
guard let lowerBound = Version(lowerBoundString) else {
throw InternalError("invalid version \(lowerBoundString)")
}
let upperBoundString = try json.get(String.self, forKey: "upperBound")
guard let upperBound = Version(string: upperBoundString) else {
guard let upperBound = Version(upperBoundString) else {
throw InternalError("invalid version \(upperBoundString)")
}
self = .range(lowerBound ..< upperBound)

case "exact":
let versionString = try json.get(String.self, forKey: "identifier")
guard let version = Version(string: versionString) else {
guard let version = Version(versionString) else {
throw InternalError("invalid version \(versionString)")
}
self = .exact(version)
Expand Down
8 changes: 4 additions & 4 deletions Sources/SPMTestSupport/MockDependencyGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public extension MockDependencyGraph {
let (container, version) = value
guard case .string(let str) = version else { fatalError() }
let package = PackageReference.remote(identity: PackageIdentity(url: container.lowercased()), location: "/\(container)")
return (package, Version(string: str)!)
return (package, Version(str)!)
})
self.name = name
self.constraints = constraints.map(PackageContainerConstraint.init(json:))
Expand All @@ -67,7 +67,7 @@ private extension MockPackageContainer {
var depByVersion: [Version: [(container: String, versionRequirement: VersionSetSpecifier)]] = [:]
for (version, deps) in versions {
guard case .array(let depArray) = deps else { fatalError() }
depByVersion[Version(string: version)!] = depArray
depByVersion[Version(version)!] = depArray
.map(PackageContainerConstraint.init(json:))
.map { constraint in
switch constraint.requirement {
Expand Down Expand Up @@ -109,11 +109,11 @@ private extension VersionSetSpecifier {
switch arr.count {
case 1:
guard case .string(let str) = arr[0] else { fatalError() }
self = .exact(Version(string: str)!)
self = .exact(Version(str)!)
case 2:
let versions = arr.map { json -> Version in
guard case .string(let str) = json else { fatalError() }
return Version(string: str)!
return Version(str)!
}
self = .range(versions[0] ..< versions[1])
default: fatalError()
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPMTestSupport/MockPackageContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class MockPackageContainer: PackageContainer {
dependencies: [String: [Dependency]] = [:]
) {
self.package = package
self._versions = dependencies.keys.compactMap(Version.init(string:)).sorted()
self._versions = dependencies.keys.compactMap(Version.init(_:)).sorted()
self.dependencies = dependencies
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPMTestSupport/MockWorkspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public final class MockWorkspace {
let versions: [String?] = packageKind == .remote ? package.versions : [nil]
let manifestPath = packagePath.appending(component: Manifest.filename)
for version in versions {
let v = version.flatMap(Version.init(string:))
let v = version.flatMap(Version.init(_:))
manifests[.init(url: packageLocation, version: v)] = Manifest(
name: package.name,
path: manifestPath,
Expand Down
2 changes: 1 addition & 1 deletion Tests/PackageGraphTests/PubgrubTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2106,7 +2106,7 @@ public class MockContainer: PackageContainer {
) {
self.package = package
self.dependencies = dependencies
let versions = dependencies.keys.compactMap(Version.init(string:))
let versions = dependencies.keys.compactMap(Version.init(_:))
self._versions = versions
.sorted()
.map(BoundVersion.version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private class MockRepository: Repository {
}

func resolveRevision(tag: String) throws -> Revision {
assert(self.versions.index(forKey: Version(string: tag)!) != nil)
assert(self.versions.index(forKey: Version(tag)!) != nil)
return Revision(identifier: tag)
}

Expand All @@ -69,7 +69,7 @@ private class MockRepository: Repository {
}

func openFileView(revision: Revision) throws -> FileSystem {
assert(self.versions.index(forKey: Version(string: revision.identifier)!) != nil)
assert(self.versions.index(forKey: Version(revision.identifier)!) != nil)
// This is used for reading the tools version.
return self.fs
}
Expand Down