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.
This commit is contained in:
parent
d465f500e3
commit
d29ac65d4d
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user