apple / swift-corelibs-foundation

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

[SR-11307] `.isAbsolutePath` is available on `String` in Swift, not ObjC Foundation #3393

Open compnerd opened 5 years ago

compnerd commented 5 years ago
Previous ID SR-11307
Radar None
Original Reporter @compnerd
Type Bug
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Foundation | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 2d04e5a2eb2c862d437d6e88592d3373

Issue Description:

import Foundation
func IsAbsolutePath(_ path: String) -> Bool {
  return path.isAbsolutePath
} 

This behaves differently across ObjC and Swift Foundation. The latter permits this, the former does not:

/Users/buildnode/jenkins/workspace/swift-package-manager-PR-osx-smoke-test/swiftpm/Sources/Basic/Path.swift:107:24: error: value of type 'String' has no member 'isAbsolutePath'
21:22:47             guard path.isAbsolutePath else {
21:22:47                   ~~~~ ^~~~~~~~~~~~~~
21:22:47 /Users/buildnode/jenkins/workspace/swift-package-manager-PR-osx-smoke-test/swiftpm/Sources/Basic/Path.swift:565:25: error: value of type 'String' has no member 'isAbsolutePath'
21:22:47     precondition(string.isAbsolutePath, "Failure normalizing \(string)")
21:22:47                  ~~~~~~ ^~~~~~~~~~~~~~ 
compnerd commented 5 years ago

CC: @millenomi

spevans commented 5 years ago

isAbsolutePath is a method on NSString - see https://developer.apple.com/documentation/foundation/nsstring/1409068-isabsolutepath

This looks to be a dupe of https://bugs.swift.org/browse/SR-10916 in which swift on linux seems to auto bridge NSString methods to String and allows them to work