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.
This commit is contained in:
Mihaela Mihaljevic 2026-07-18 23:49:16 +02:00
parent d29ac65d4d
commit f1bf9e7a18

View File

@ -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 {