diff --git a/Tests/TaggedNodeCorpusRoundTripTests.swift b/Tests/TaggedNodeCorpusRoundTripTests.swift index 6fea503..4aca297 100644 --- a/Tests/TaggedNodeCorpusRoundTripTests.swift +++ b/Tests/TaggedNodeCorpusRoundTripTests.swift @@ -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 {