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-6473] Generic subscripts don't work as protocol requirements #49023

Closed
lattner mannequin opened this issue Nov 25, 2017 · 3 comments
Closed

[SR-6473] Generic subscripts don't work as protocol requirements #49023

lattner mannequin opened this issue Nov 25, 2017 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@lattner
Copy link
Mannequin

lattner mannequin commented Nov 25, 2017

Previous ID SR-6473
Radar None
Original Reporter @lattner
Type Bug
Status Resolved
Resolution Invalid
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: edcc85d2bd744a54b39f3b6c82f8aef2

Issue Description:

I'd really like for this to be possible:

public protocol P1 {
subscript<T2> () -> T2 { get }
}
struct Impl : P1 {
subscript() -> Int {
return 42
}
}

we currently reject it incorrectly like this:

t.swift:49:8: error: type 'Impl' does not conform to protocol 'P1'
struct Impl : P1 {
^
t.swift:50:3: note: candidate has non-matching type '() -> Int'
subscript() -> Int {
^
t.swift:46:3: note: protocol requires subscript with type '<T2> () -> T2'; do you want to add a stub?
subscript<T2> () -> T2 { get }
^

@lattner
Copy link
Mannequin Author

lattner mannequin commented Nov 25, 2017

@slavapestov, @DougGregor, is this a shallow bug or something really deep?

-Chris

@DougGregor
Copy link
Member

The example as written is ill-formed, because Impl’s subscript needs to be generic as well. If generic subscripts are actually broken in protocols, I’d expect the bug to be shallow.

@slavapestov
Copy link
Member

This works:

public protocol P1 {
  subscript<T2> (t: T2) -> T2 { get }
}

struct Impl : P1 {
  subscript<T2>(t: T2) -> T2 { return t }
}

@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
Projects
None yet
Development

No branches or pull requests

2 participants