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-11022] [Opaque Result Types] definition in protocols allowed but error in protocol implementation #53412

Closed
swift-ci opened this issue Jun 26, 2019 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself conformances Feature → protocol: protocol conformances opaque types Feature → types: opaque types

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11022
Radar rdar://problem/50678247
Original Reporter GLanza (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, OpaqueResultTypes, ProtocolConformance
Assignee None
Priority Medium

md5: 0d1957e9924647428567b18a8bbe6ce5

Issue Description:

It is currently allowed by the compiler to define variables having opaque result types, but creating objects conforming these protocols generates a compiler error.

Example:

protocol Foo {
    associatedtype FooType
}


protocol Bar {
    var barvar: some Foo { get } //No complains here
}


struct RealFoo: Foo {
    typealias FooType = Any
}


struct Baz: Bar { // The compiler assert that Baz does not conform Bar
    var barvar: some Foo { RealFoo() } 
}

Nt sure if the bug is in the fact that protocols should not allow the definition of opaque pointers to avoid associated types or in the fact that the compiler is wrongfully erroring a legitimate conformance... either ways there is something wrong here.

In the first case, the compiler should not allow the definition of var barvar: some Foo { get } in the protocol.

In the second case, Baz should be considered conformant to Bar as it fullfils all the requirements.

@belkadan
Copy link
Contributor

Yeah, it's already been disallowed in master, and will be disallowed in future Xcode 11 betas.

@swift-ci
Copy link
Collaborator Author

Comment by Giuseppe Lanza (JIRA)

Thank you! 🙂

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

No branches or pull requests

2 participants