apple / swift-corelibs-foundation

The Foundation Project, providing core utilities, internationalization, and OS independence
swift.org
Apache License 2.0
5.23k stars 1.12k forks source link

`Data(contentsOf:)` regression on Windows in Swift 5.10 #4921

Open tishin opened 3 months ago

tishin commented 3 months ago

A simple script to reproduce the issue:

import Foundation

let url = URL(fileURLWithPath: "/Projects/file.txt")
if FileManager.default.fileExists(atPath: url.path) {
    print(try Data(contentsOf: url))
}

It works in Swift 5.9.2 release, but throws an error in Swift 5.10 release:

Swift/ErrorType.swift:200: Fatal error: Error raised at top level: Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"
Current stack trace:
0    (null)                             0x00007ffca6a24ae0 swift_stdlib_reportFatalErrorInFile + 132

Swift version 5.10 (swift-5.10-RELEASE) Target: x86_64-unknown-windows-msvc OS Version: 10.0.19045 N/A Build 19045

Possibly introduced by #4802