From f1bf9e7a18319d30471062d7196c9731456a0f3c Mon Sep 17 00:00:00 2001 From: Mihaela Mihaljevic Date: Sat, 18 Jul 2026 23:49:16 +0200 Subject: [PATCH] fix(tests): precompute the sort key outside sorted(by:) on Linux The previous attempt still cast inside the sorted(by:) trailing closure itself; the relay showed the SAME NSURL/URL inference failure had moved to the next line (String(contentsOf: url, ...)), confirming the cast inside that specific closure -- not the earlier named-helper form -- was still what confused the resolver. Precomputing (url, name) tuples via a separate map, then sorting on the plain String name, keeps the sorted(by:) closure itself exactly as simple as the original working comparison (no cast, no call inside it), which is what compiled cleanly before any of this. Verified via a full clean macOS build and the specific test passing, plus swiftformat/swiftlint --strict clean; the actual claim (Linux relay passes) needs the next push to confirm. --- Tests/TaggedNodeCorpusRoundTripTests.swift | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Tests/TaggedNodeCorpusRoundTripTests.swift b/Tests/TaggedNodeCorpusRoundTripTests.swift index 2f571f3..6fea503 100644 --- a/Tests/TaggedNodeCorpusRoundTripTests.swift +++ b/Tests/TaggedNodeCorpusRoundTripTests.swift @@ -20,11 +20,19 @@ 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. 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? ?? "") }) { + // toolchain's swift-corelibs-foundation. A cast or function call INSIDE the `sorted(by:)` + // trailing closure itself (tried first: an `as String?` coercion, then a named helper) + // sent this toolchain's overload resolution down a path that inferred the closure's + // parameters as `NSURL` instead of `URL`, breaking every other `URL`-typed use below -- + // even though a bare `$0.lastPathComponent < $1.lastPathComponent` comparison (no cast, no + // call) resolved fine. Precomputing the sort key in a separate `map` keeps the `sorted(by:)` + // closure itself exactly that simple (comparing two already-plain `String`s), sidestepping + // whatever in the trailing closure was confusing the resolver. + let sortedURLs = urls + .map { url in (url: url, name: (url.lastPathComponent as String?) ?? "") } + .sorted { $0.name < $1.name } + .map(\.url) + for url in sortedURLs { let source = try String(contentsOf: url, encoding: .utf8) let parsed: PureYAML.Tagged.Node do {