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-7348] Using symbols in protocol extensions doesn't always check where-clauses for allowable symbols. #49896

Open
swift-ci opened this issue Apr 4, 2018 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 4, 2018

Previous ID SR-7348
Radar None
Original Reporter CTMacUser (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 814da93b5b8c456ddd7f8b62a26aac10

Issue Description:

Start with:

public enum InvertedRange<Index: Comparable> {
    case beforeStart, afterEnd, all
    case prefix(upThrough: Index)
    case range(after: Index, upThrough: Index)
    case suffix(after: Index)
}

public protocol TransferableCollection: MutableCollection /*[[1]]*/ where /*[[2]]*/ Self.SubSequence: TransferableCollection {}

extension TransferableCollection /*[[3]]*/ {

    private func convertRange(_ range: InvertedRange<Index>) -> Range<Index>
    { /*...*/ }

    private func convertRange<R>(_ range: R) -> InvertedRange<Index> where R: RangeExpression, R.Bound == Index {
        let r = range.relative(to: self)
        switch (r.lowerBound, r.upperBound) {
        case (startIndex, endIndex): return .all
        case (startIndex, startIndex): return .beforeStart
        case (startIndex, let i): return .prefix(upThrough: index(before: i)) // ERROR HERE
        case (let i, endIndex): return .suffix(after: index(before: i)) // AND HERE
        case (endIndex, endIndex): return .afterEnd
        case (let s, let e): return .range(after: index(before: s), upThrough: index(before: e)) // AND HERE
        }
    }

}

Where there are three errors at the lines that call the base BidirectionalCollection method, index(before: ). The error is:

Argument labels '(before:)' do not match any available overloads 

This can be remedied by replacing comment-spot #3 with:

where Self: BidirectionalCollection 

But I should be able to do that in the primary definition. If I put comment-spot #3 back into a comment and replace comment-spot #2 with:

Self: BidirectionalCollection,

it should also correct the problem, but it doesn't. Worse, putting the declaration in comment-spot #3 again this time does not fix it!

However, if I turn comment-spots #2 and #3 back into comments, and replace comment-spot #1 with:

, BidirectionalCollection

Then the code in the extension block works. (Putting the where-clause back in comment-spot #3 doesn't change anything this time.)

@belkadan
Copy link
Contributor

belkadan commented Apr 5, 2018

cc @huonw

@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

2 participants