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-15466] Duplicated error message for type that doesn't conform to protocol #57771

Open
swift-ci opened this issue Nov 9, 2021 · 0 comments
Labels
compiler The Swift compiler in itself improvement

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Nov 9, 2021

Previous ID SR-15466
Radar None
Original Reporter vinivendra (JIRA User)
Type Improvement

Attachment: Download

Environment

MacOS 12.0.1 - Swift 5.5.1

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

md5: 97d7a14edb4c17bb51d50a8b40a74503

relates to:

  • SR-15467 Confusing error message for unavailable member when conforming to protocol

Issue Description:

When creating a type that conforms to Collection, create implementations for all requirements except for `subscript(bounds: Range<Index>) -> Subsequence`. This will cause the compiler to try to satisfy this requirement with an unavailable subscript, which will raise the following error:

test.swift:2:15: error: type '_ListSlice<Element>' does not conform to protocol 'Collection'
public struct _ListSlice<Element>: Collection,
              ^
test.swift:2:15: error: unavailable subscript 'subscript(_:)' was used to satisfy a requirement of protocol 'Collection'
public struct _ListSlice<Element>: Collection,
              ^
Swift.Collection:3:12: note: 'subscript(_:)' declared here
    public subscript(bounds: Range<Self.Index>) -> Self.SubSequence { get }
           ^
Swift.Collection:12:5: note: requirement 'subscript(_:)' declared here
    subscript(bounds: Range<Self.Index>) -> Self.SubSequence { get }
    ^

If the type also declares that it conforms to refined types such as BidirectionalCollection, RandomAccessCollection, and RangeReplaceableCollection, the error message and the notes will be duplicated once for every additional protocol:

test.swift:2:15: error: type '_ListSlice<Element>' does not conform to protocol 'BidirectionalCollection'
public struct _ListSlice<Element>: Collection,
              ^
test.swift:2:15: error: unavailable subscript 'subscript(_:)' was used to satisfy a requirement of protocol 'BidirectionalCollection'
public struct _ListSlice<Element>: Collection,
              ^
Swift.Collection:3:12: note: 'subscript(_:)' declared here
    public subscript(bounds: Range<Self.Index>) -> Self.SubSequence { get }
           ^
Swift.BidirectionalCollection:14:14: note: requirement 'subscript(_:)' declared here
    override subscript(bounds: Range<Self.Index>) -> Self.SubSequence { get }
             ^
test.swift:2:15: error: type '_ListSlice<Element>' does not conform to protocol 'RandomAccessCollection'
public struct _ListSlice<Element>: Collection,
              ^
test.swift:2:15: error: unavailable subscript 'subscript(_:)' was used to satisfy a requirement of protocol 'RandomAccessCollection'
public struct _ListSlice<Element>: Collection,
              ^
Swift.Collection:3:12: note: 'subscript(_:)' declared here
    public subscript(bounds: Range<Self.Index>) -> Self.SubSequence { get }
           ^
Swift.RandomAccessCollection:7:14: note: requirement 'subscript(_:)' declared here
    override subscript(bounds: Range<Self.Index>) -> Self.SubSequence { get }
             ^
test.swift:2:15: error: type '_ListSlice<Element>' does not conform to protocol 'RangeReplaceableCollection'
public struct _ListSlice<Element>: Collection,
              ^
test.swift:2:15: error: unavailable subscript 'subscript(_:)' was used to satisfy a requirement of protocol 'RangeReplaceableCollection'
public struct _ListSlice<Element>: Collection,
              ^
Swift.Collection:3:12: note: 'subscript(_:)' declared here
    public subscript(bounds: Range<Self.Index>) -> Self.SubSequence { get }
           ^
Swift.RangeReplaceableCollection:23:14: note: requirement 'subscript(_:)' declared here
    override subscript(bounds: Range<Self.Index>) -> Self.SubSequence { get }
             ^

This may cause the user to incorrectly assume that there is more than one problem in the code, and makes it harder to understand that the real problem is in the conformance to Collection (as opposed to the other protocols).

The attached test.swift file causes these errors in Swift 5.5.1.

@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
compiler The Swift compiler in itself improvement
Projects
None yet
Development

No branches or pull requests

1 participant