From d29ac65d4d7f78561db588c31e7a80efc311b059 Mon Sep 17 00:00:00 2001 From: Mihaela Mihaljevic Date: Sat, 18 Jul 2026 23:46:48 +0200 Subject: [PATCH] fix(tests): avoid a URL/NSURL bridging mismatch in the sort closure The prior fix's separate `func name(_ url: URL) -> String` helper, called as `name($0)`/`name($1)` inside the sort closure, made the Linux relay fail differently: "'NSURL' is not implicitly convertible to 'URL'" at both call sites, even though the surrounding loop's `url` (same array, same element) type-checked fine everywhere else. Declaring no explicit URL parameter type anywhere and inlining the `as String? ?? ""` coercion directly at each of the three use sites sidesteps whatever overload-resolution path the named helper's concrete parameter type was forcing. Verified via a full clean macOS build and test run (the specific test passing) and swiftformat/swiftlint --strict clean; the actual claim (Linux relay passes) still needs the next push to confirm, since this Foundation/bridging behavior cannot be reproduced on macOS directly. --- Tests/TaggedNodeCorpusRoundTripTests.swift | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Tests/TaggedNodeCorpusRoundTripTests.swift b/Tests/TaggedNodeCorpusRoundTripTests.swift index 3fdcef5..2f571f3 100644 --- a/Tests/TaggedNodeCorpusRoundTripTests.swift +++ b/Tests/TaggedNodeCorpusRoundTripTests.swift @@ -19,14 +19,12 @@ struct TaggedNodeCorpusRoundTripTests { )) var accepted = 0 var rejected = 0 - /// `URL.lastPathComponent` is `String` on Darwin's Foundation but `String?` on this - /// toolchain's swift-corelibs-foundation; the explicit `as String?` upcast/coercion makes - /// both platforms produce a uniform `String?` here so `?? ""` compiles identically either - /// way, rather than picking one platform's non-optional type and breaking the other. - func name(_ url: URL) -> String { - (url.lastPathComponent as String?) ?? "" - } - for url in urls.sorted(by: { name($0) < name($1) }) { + // `URL.lastPathComponent` is `String` on Darwin's Foundation but `String?` on this + // toolchain's swift-corelibs-foundation. Left deliberately untyped (no explicit `URL` + // parameter anywhere below) since a fixed `Bundle.module.urls(...)` result element type + // also varies across those two Foundations; the `as String?` coercion after the property + // access, not before, is what stays valid on both. + for url in urls.sorted(by: { ($0.lastPathComponent as String? ?? "") < ($1.lastPathComponent as String? ?? "") }) { let source = try String(contentsOf: url, encoding: .utf8) let parsed: PureYAML.Tagged.Node do { @@ -41,11 +39,11 @@ struct TaggedNodeCorpusRoundTripTests { do { reparsed = try PureYAML.parseTagged(dumped) } catch { - Issue.record("\(name(url)): dump produced unparseable YAML: \(error)") + Issue.record("\(url.lastPathComponent as String? ?? ""): dump produced unparseable YAML: \(error)") continue } if let detail = firstDivergence(parsed, reparsed, path: "$") { - Issue.record("\(name(url)): \(detail)") + Issue.record("\(url.lastPathComponent as String? ?? ""): \(detail)") } } #expect(accepted > 0)