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-6474] Conditional conformance to refined protocol inappropriately fails #49024

Closed
xwu opened this issue Nov 25, 2017 · 5 comments
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself conditional conformances Feature → protocol → conformances: conditional conformances

Comments

@xwu
Copy link
Collaborator

xwu commented Nov 25, 2017

Previous ID SR-6474
Radar rdar://problem/38754177
Original Reporter @xwu
Type Bug
Status Closed
Resolution Done
Environment

Swift snapshot 2017-11-24 (a)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, ConditionalConformance
Assignee @DougGregor
Priority Medium

md5: 831a0c9866177c91e932d3d199ddbb0c

duplicates:

  • SR-7327 Conditional conformance does not conform to inherited protocol

is duplicated by:

  • SR-6914 Extensions don't add conformance to inherited protocols
  • SR-7253 Conditional conformance to P fails if P inherits from two other protocols, but not for eg Array

relates to:

  • SR-6840 Confusing error in conditional conformance
  • SR-6650 Conditional conformance not identifying protocol extension implementation
  • SR-6922 [SE-0143] [release mode] type ... does not conform to protocol ...

Issue Description:

The following code fails to compile with the 2017-11-24 snapshot.

protocol P {
  var count: Int { get }
}

protocol Q : P { }

// ---

struct S<T> { }

extension S : Q where T : Equatable {
  var count: Int { return 1 }
}

// ---

func f<T : P>(_ p: T) {
  print(p.count)
}

f(S<Int>())

Changing extension S : Q where... to extension S : P where... allows the code to compile, but of course S : Q should imply S : P.

Meanwhile, that workaround never permits S to conform to Q. That is, the following fails to compile:

struct S<T> { }

extension S : P where T : Equatable {
  var count: Int { return 1 }
}

extension S : Q where T : Equatable { }

(The practical upshot of this is that StrideTo cannot conditionally conform to RandomAccessCollection because that protocol exists in a hierarchy refining other protocols.)

@belkadan
Copy link
Contributor

cc @DougGregor

@DougGregor
Copy link
Member

The original example is failing because we don't seem to be implementing the placement rules for implied conditional conformances (https://github.com/apple/swift-evolution/blob/master/proposals/0143-conditional-conformances.md#implied-conditional-conformances).

However, with master, explicitly declaring the `S: P` conformance works around the issue.

@belkadan
Copy link
Contributor

@swift-ci create

@belkadan
Copy link
Contributor

Interesting observation from SR-7253: it works with stdlib types, just not types defined in source.

@huonw
Copy link
Mannequin

huonw mannequin commented Apr 5, 2018

The compiler previously didn't accept implicit conditional conformance in a broken way, leading to inconsistencies and brokenness like this. As of apple/swift-evolution#809 the rule Doug mentions above has changed, and #15268 implements it, so the compiler prompts for the explicit conformance (and offers help to write it via a few different fixits)

@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 conditional conformances Feature → protocol → conformances: conditional conformances
Projects
None yet
Development

No branches or pull requests

3 participants