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-4103] Allow protocol conformance by promoting property getter of type T to T? #46686

Closed
nolanw opened this issue Feb 28, 2017 · 2 comments
Closed
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

@nolanw
Copy link

nolanw commented Feb 28, 2017

Previous ID SR-4103
Radar None
Original Reporter @nolanw
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 64f4cc77ff7834aa2d84df3814458644

duplicates:

  • SR-522 Protocol funcs cannot have covariant returns

Issue Description:

Hello! I think I should be allowed to do this:

protocol P {
    var count: Int? { get }
}

class C: P {
    let count: Int = 5
}

because I can usually assign or pass a T anywhere an Optional<T> is required. But instead I get a compile error:

error: type 'C' does not conform to protocol 'P'
class C: P {
      ^

note: candidate has non-matching type 'Int'
    let count: Int = 5
        ^

This would only be allowed if the protocol specifies a non-settable property. If the protocol requires a setter then a compile error is still appropriate.

@belkadan
Copy link
Contributor

belkadan commented Mar 1, 2017

Consolidating.

@nolanw
Copy link
Author

nolanw commented Mar 1, 2017

No chance I ever would've stumbled upon that issue with the search terms I was guessing! Thanks for the pointer.

@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 type checker Area → compiler: Semantic analysis conformances Feature → protocol: protocol conformances protocol Feature → type declarations: Protocol declarations compiler The Swift compiler in itself 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