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-629] Protocol composition types should be covariant with composing protocols for protocol conformance #43246

Closed
swift-ci opened this issue Jan 27, 2016 · 1 comment
Labels
compiler The Swift compiler in itself conformances Feature → protocol: protocol conformances duplicate Resolution: Duplicates another issue feature A feature request or implementation improvement protocol Feature → type declarations: Protocol declarations type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jan 27, 2016

Previous ID SR-629
Radar None
Original Reporter ianterrell (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Mac OS 10.11.1 (15B42)
Xcode 7.2 (7C68)

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

md5: d960735cf0599949e4c6f4948a07a6d4

duplicates:

  • SR-522 Protocol funcs cannot have covariant returns

relates to:

  • SR-2020 Protocol composition doesn't conform to associated type requirement

Issue Description:

The type protocol<A,B> should be treated as covariant with the type A since all types conforming to protocol<A,B> conform to A.

This works for function calling:

protocol A {}
protocol B {}
struct Foo: A, B {}
func bar(a: A) {}
let composite: protocol<A,B> = Foo()
bar(composite)

However, it does not work for protocol conformance. Given A and B above, I expect the following to compile, but it does not:

protocol HasA {
    var a: A { get }
}
struct Baz: HasA {
    var a: protocol<A,B>
}

Similarly, I expect function return values to work as well, but this does not compile:

protocol Baffer {
    func baf() -> A
}
struct Baz: Baffer {
    func baf() -> protocol<A,B> { return Foo() }
}
@belkadan
Copy link
Contributor

We don't currently allow any covariance in protocol conformance.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added duplicate Resolution: Duplicates another issue feature A feature request or implementation conformances Feature → protocol: protocol conformances protocol Feature → type declarations: Protocol declarations type checker Area → compiler: Semantic analysis improvement and removed bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. labels Jan 27, 2023
This issue was closed.
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 conformances Feature → protocol: protocol conformances duplicate Resolution: Duplicates another issue feature A feature request or implementation improvement protocol Feature → type declarations: Protocol declarations type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants