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-12980] Making protocol inherit CaseIterable produces nonsensical errors #55426

Closed
jepers opened this issue Jun 11, 2020 · 3 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@jepers
Copy link

jepers commented Jun 11, 2020

Previous ID SR-12980
Radar rdar://problem/88514540
Original Reporter @jepers
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 1
Component/s
Labels Bug
Assignee None
Priority Medium

md5: ffff7ab8fd7dbc98f69de8dba225a412

Issue Description:

This program compiles as expected:

protocol VectorIndex {}

protocol Vector {
  associatedtype Element
  associatedtype Index: VectorIndex
  subscript(index: Index) -> Element { get set }
  init(_ indexToElementMapping: (Index) -> Element)
}

// Some methods for square matrices:
extension Vector where
  Self.Element: Vector,
  Self.Index == Self.Element.Index,
  Self.Element.Element: BinaryFloatingPoint
{
  func row(_ index: Index) -> Element { self[index] }

  func column(_ index: Index) -> Element { Element { self[$0][index] } }
}

But note that if we make VectorIndex inherit/refine CaseIterable, like so:

protocol VectorIndex: CaseIterable {}

The program will no longer compile, because:

error: cannot convert value of type 'Self.Element.Index' (associated type of protocol 'Vector') to expected argument type 'Self.Index' (associated type of protocol 'Vector')

ie, it seems like the constraint Self.Index == Self.Element.Index is now being ignored.

@slavapestov
Copy link
Member

This now works with -requirement-machine-inferred-signatures=on; I'll add a regression test.

@slavapestov
Copy link
Member

@swift-ci create

@slavapestov
Copy link
Member

#42113

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

No branches or pull requests

2 participants