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-4664] Bad diagnostic passing incorrect type to method in generic type #47241

Closed
NachoSoto opened this issue Apr 21, 2017 · 4 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis

Comments

@NachoSoto
Copy link
Contributor

Previous ID SR-4664
Radar rdar://problem/31764828
Original Reporter @NachoSoto
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 3.1 (swiftlang-802.0.53 clang-802.0.42)

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

md5: c0118e87c48248a5048d979e49a82d3c

Issue Description:

This code:

struct M<T> where T : Collection {
    static func f(a: T, b: T) -> [E<T.Iterator.Element>] {
    
    }
}

enum E<T> {}

struct S {}

struct X {
    struct Y {
        let s: [S]
    }

    let y: [Y]
}

let x = X(y: [])

let a = M.f(a: x.y[0], b: x.y[1])

Produces:

error: repl.swift:26:19: error: ambiguous reference to member 'subscript'
let a = M.f(a: x.y[0], b: x.y[1])
               ~~~^~~

Swift.Array:402:12: note: found this candidate
    public subscript(index: Int) -> Element { get set }
           ^

Swift.Array:429:12: note: found this candidate
    public subscript(bounds: Range<Int>) -> ArraySlice<Element> { get set }
           ^

Swift.RangeReplaceableCollection:2:12: note: found this candidate
    public subscript(bounds: Range<Self.Index>) -> RangeReplaceableSlice<Self> { get }
           ^

Swift.RangeReplaceableCollection:2:12: note: found this candidate
    public subscript(bounds: Range<Self.Index>) -> MutableRangeReplaceableSlice<Self> { get set }
           ^

Swift.RangeReplaceableCollection:2:12: note: found this candidate
    public subscript(bounds: Range<Self.Index>) -> RangeReplaceableBidirectionalSlice<Self> { get }
           ^

Swift.RangeReplaceableCollection:2:12: note: found this candidate
    public subscript(bounds: Range<Self.Index>) -> MutableRangeReplaceableBidirectionalSlice<Self> { get set }
           ^

Swift.RangeReplaceableCollection:2:12: note: found this candidate
    public subscript(bounds: Range<Self.Index>) -> RangeReplaceableRandomAccessSlice<Self> { get }
           ^

Swift.RangeReplaceableCollection:2:12: note: found this candidate
    public subscript(bounds: Range<Self.Index>) -> MutableRangeReplaceableRandomAccessSlice<Self> { get set }
           ^

Swift.RandomAccessCollection:26:12: note: found this candidate
    public subscript(bounds: Range<Self.Index>) -> RandomAccessSlice<Self> { get }
           ^

Swift.BidirectionalCollection:5:12: note: found this candidate
    public subscript(bounds: Range<Self.Index>) -> BidirectionalSlice<Self> { get }
           ^

Swift._MutableIndexable:24:12: note: found this candidate
    public subscript(bounds: ClosedRange<Self.Index>) -> Self.SubSequence { get set }
           ^

Swift._MutableIndexable:24:12: note: found this candidate
    public subscript(bounds: CountableRange<Self.Index>) -> Self.SubSequence { get set }
           ^

Swift._MutableIndexable:47:12: note: found this candidate
    public subscript(bounds: CountableClosedRange<Self.Index>) -> Self.SubSequence { get set }
           ^

Swift._Indexable:23:12: note: found this candidate
    public subscript(bounds: ClosedRange<Self.Index>) -> Self.SubSequence { get }
           ^

Swift._Indexable:23:12: note: found this candidate
    public subscript(bounds: CountableRange<Self.Index>) -> Self.SubSequence { get }
           ^

Swift._Indexable:45:12: note: found this candidate
    public subscript(bounds: CountableClosedRange<Self.Index>) -> Self.SubSequence { get }
           ^

Swift.Collection:27:12: note: found this candidate
    public subscript(bounds: Range<Self.Index>) -> Slice<Self> { get }
           ^

Swift.MutableCollection:25:12: note: found this candidate
    public subscript(bounds: Range<Self.Index>) -> MutableSlice<Self> { get set }
           ^

Swift.MutableCollection:2:12: note: found this candidate
    public subscript(bounds: Range<Self.Index>) -> MutableBidirectionalSlice<Self> { get set }
           ^

Swift.MutableCollection:2:12: note: found this candidate
    public subscript(bounds: Range<Self.Index>) -> MutableRandomAccessSlice<Self> { get set }
           ^

Instead of telling me something more useful, like the fact that `x.y[index]` is type `Y`, which doesn't conform to `Collection`.

@jckarter
Copy link
Member

@swift-ci create

@NachoSoto
Copy link
Contributor Author

Wow, surprised! This is fixed in Swift 4.0. I'm gonna leave it open to make sure that you guys add regression tests for this.

@slavapestov
Copy link
Member

I updated the radar with a note to add a regression test.

@NachoSoto
Copy link
Contributor Author

Thanks @slavapestov!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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 diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants