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-8011] The curious case of protocol with class conformance and casting… #50544

Closed
iby opened this issue Jun 15, 2018 · 6 comments
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@iby
Copy link

iby commented Jun 15, 2018

Previous ID SR-8011
Radar None
Original Reporter @iby
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee @slavapestov
Priority Medium

md5: e922b9307dc02f25977e8e9031a28bb6

duplicates:

  • SR-6816 Let protocols inherit from class types

Issue Description:

Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)
Target: x86_64-apple-darwin17.6.0

@belkadan
Copy link
Contributor

The second line fails because once you have a MyProtocol value, the compiler forgets where it came from, and so it could be some other type that conforms to MyProtocol. But the last line really ought to work! Sounds like more of the badness around protocols with superclass constraints.

cc @slavapestov

@belkadan
Copy link
Contributor

With asserts:

TYPE MISMATCH IN ARGUMENT 0 OF APPLY AT expression at [<stdin>:16:17 - line:16:32] RangeText="as MyProtocol).f"
  argument value:   %82 = alloc_stack $@opened("D2FA264A-7314-11E8-8817-9A0002AC2BC0") (MyProtocol) // type-defs: %81; user: %83
  parameter type: $@opened("D2FA264A-7314-11E8-8817-9A0002AC2BC0") (MyProtocol)

@iby
Copy link
Author

iby commented Jun 18, 2018

so it could be some other type that conforms to MyProtocol

Perhaps I'm not getting how where clause works – I thought it's kind of the same as regular inheritance, the outcome at least… I was going for a counter argument that the following works, but compiler also fails to build with a redundant conformance warning followed by a crash. Perhaps a separate issue?

@belkadan
Copy link
Contributor

Oops, my brain dropped the where clause from the first half of the answer. You're right, the compiler could allow that. Can we track that in a separate bug?

@iby
Copy link
Author

iby commented Jun 18, 2018

Separated into SR-8031 and SR-8032.

@slavapestov
Copy link
Member

Protocol 'where' clauses don't support constraints on Self yet.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 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 crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

4 participants