fix(tests): sort plain Int indices, never a derived URL array

Precomputing (url, name) tuples and mapping back to [URL] via a
keypath still put a URL through a map/sorted chain, and the relay
showed the SAME NSURL/URL inference failure moved one line further
down (String(contentsOf:) on the loop variable this time).

Sorting names.indices (plain Int) and subscripting the ORIGINAL,
never-transformed urls array at the one point each URL is used
removes every map/sorted call from ever touching a URL-typed value
at all, keeping the one place a URL is read structurally identical
to a bare `for url in urls` (confirmed safe from the very first
relay run, before any of these fix attempts).

Verified via a full clean macOS build, the specific test passing,
and swiftformat/swiftlint --strict clean; the Linux relay is the
actual proof and needs the next push to confirm.
This commit is contained in:
Mihaela Mihaljevic 2026-07-18 23:51:57 +02:00
parent f1bf9e7a18
commit ecd1b34a18

View File

@ -20,19 +20,17 @@ 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. 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 {
// toolchain's swift-corelibs-foundation. Every attempt to derive a `[URL]` THROUGH a
// `map`/`sorted` chain touching `.lastPathComponent` -- an inline cast, a named helper, a
// tuple-and-keypath precompute -- came back from the Linux relay with `url` re-inferred as
// `NSURL` somewhere downstream, breaking `String(contentsOf:encoding:)`. Sorting the plain
// `Int` INDICES instead keeps every `.sorted(by:)`/`.map` in this file entirely divorced
// from any URL-typed value; `urls[index]` below is the one and only place a `URL` from the
// original, never-transformed array is touched, so its type can never drift.
let names = urls.map { ($0.lastPathComponent as String?) ?? "" }
let order = names.indices.sorted { names[$0] < names[$1] }
for index in order {
let url = urls[index]
let source = try String(contentsOf: url, encoding: .utf8)
let parsed: PureYAML.Tagged.Node
do {