Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-7029] on Darwin String.hasPrefix seems to be in the stdlib, on Linux it's not #3734

Closed
weissi opened this issue Feb 19, 2018 · 5 comments

Comments

@weissi
Copy link
Member

weissi commented Feb 19, 2018

Previous ID SR-7029
Radar None
Original Reporter @weissi
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Foundation, Standard Library
Labels Bug
Assignee @airspeedswift
Priority Medium

md5: 29ba569747314d2a0051173965e32872

Issue Description:

the following Swift code

print("abc".hasPrefix("a"))

compiled and run on Darwin gives

$ cat test.swift && swiftc -o test test.swift && ./test
print("abc".hasPrefix("a"))
true

but on Linux

$ cat test.swift && swiftc -o test test.swift && ./test
print("abc".hasPrefix("a"))
test.swift:1:7: error: value of type 'String' has no member 'hasPrefix'
print("abc".hasPrefix("a"))
      ^~~~~ ~~~~~~~~~

Swift versions 4.0.2 on both

@belkadan
Copy link

I think there was a deliberate reason for this, but I don't remember it. @milseman?

@weissi
Copy link
Member Author

weissi commented Feb 19, 2018

I should probably mention that there's Sequence.starts<S: Sequence>(with: S) where ... which obvs works on String now.

@milseman
Copy link
Mannequin

milseman mannequin commented Feb 19, 2018

@airspeedswift was working on this. On Darwin it uses NSString operations.

@airspeedswift
Copy link
Member

Right, sequence has starts(with🙂 which is the same thing (albeit slightly slower)

@spevans
Copy link
Collaborator

spevans commented Mar 5, 2020

Looks like it was fixed in 4.2

$ ~/swift-4.2-RELEASE-ubuntu18.04/usr/bin/swift
Welcome to Swift version 4.2 (swift-4.2-RELEASE). Type :help for assistance.
  1> print("abc".hasPrefix("a")) 
true 

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants