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-2758] Shadow stdlib method without warning #45362

Open
krzyzanowskim opened this issue Sep 26, 2016 · 0 comments
Open

[SR-2758] Shadow stdlib method without warning #45362

krzyzanowskim opened this issue Sep 26, 2016 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@krzyzanowskim
Copy link
Contributor

Previous ID SR-2758
Radar None
Original Reporter @krzyzanowskim
Type Bug
Environment

Swift 3.0
Xcode Version 8.0 (8A218a)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 7d718780e7221a039308f9570fa8f365

relates to:

  • SR-4660 Methods on self should not block unambiguous calls to free functions
  • SR-8524 Shadowing in protocols leads to difficult to find bugs

Issue Description:

https://gist.github.com/krzyzanowskim/a373a7d68e6808c06d6760d2a834f488

String already have hasPefix() in stdlib

public func hasPrefix(_ prefix: String) -> Bool

public func hasPrefix(_ prefix: String) -> Bool {

so I will implement identical method in my public exception:

public extension String {
    // wait wait wait... why no error here?
    public func hasPrefix(_ prefix: String) -> Bool {
        return true // fake it till you make it
    }
}

and use it. This will execute my version of String.hasPrefix(), that is rather unexpected and error prone.

let s = "abcd"
if s.hasPrefix("oooo") {
    print("hasPrefix true")
}

¯_(ツ)_/¯

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

1 participant