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-4161] Subtyping of Optionals incomplete #46744

Closed
dabrahams opened this issue Mar 5, 2017 · 0 comments
Closed

[SR-4161] Subtyping of Optionals incomplete #46744

dabrahams opened this issue Mar 5, 2017 · 0 comments
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

@dabrahams
Copy link
Collaborator

dabrahams commented Mar 5, 2017

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

md5: af2e8c8c2d3e1332669d7dbc177294a5

duplicates:

  • SR-522 Protocol funcs cannot have covariant returns

Issue Description:

Given this:

(swift) func f() -> Int { return 3 }
(swift) let g : ()->Int? = f

You'd expect all of the following to work, but they don't:

(swift) protocol P { func f(_:(Int?)->()) }
(swift) struct X : P { func f(_:(Int)->()) }
<REPL Input>:1:8: error: type 'X' does not conform to protocol 'P'
struct X : P { func f(_:(Int)->()) }
       ^
<REPL Input>:1:19: note: protocol requires function 'f' with type '((Int?) -> ()) -> ()'; do you want to add a stub?
protocol P { func f(_:(Int?)->()) }
                  ^
<REPL Input>:1:21: note: candidate has non-matching type '((Int) -> ()) -> ()'
struct X : P { func f(_:(Int)->()) }
                    ^
<REPL Input>:1:21: error: expected '{' in body of function declaration
struct X : P { func f(_:(Int)->()) }
                    ^
(swift) protocol Q { var i: Int? }
<REPL Input>:1:18: error: property in protocol must have explicit { get } or { get set } specifier
protocol Q { var i: Int? }
                 ^
(swift) protocol Q { var i: Int? {get}}
(swift) struct Y : Q { var i: Int = 0 }
<REPL Input>:1:8: error: type 'Y' does not conform to protocol 'Q'
struct Y : Q { var i: Int = 0 }
       ^
<REPL Input>:1:18: note: protocol requires property 'i' with type 'Int?'; do you want to add a stub?
protocol Q { var i: Int? {get}}
                 ^
<REPL Input>:1:20: note: candidate has non-matching type 'Int'
struct Y : Q { var i: Int = 0 }
                   ^
(swift) protocol R { func f() -> Int? }
(swift) struct Z : R { f() -> Int { return 3 } }
<REPL Input>:1:16: error: expected declaration
struct Z : R { f() -> Int { return 3 } }
               ^
<REPL Input>:1:8: note: in declaration of 'Z'
struct Z : R { f() -> Int { return 3 } }
       ^
<REPL Input>:1:8: error: type 'Z' does not conform to protocol 'R'
struct Z : R { f() -> Int { return 3 } }
       ^
<REPL Input>:1:19: note: protocol requires function 'f()' with type '() -> Int?'; do you want to add a stub?
protocol R { func f() -> Int? }
                  ^
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added duplicate Resolution: Duplicates another issue type checker Area → compiler: Semantic analysis conformances Feature → protocol: protocol conformances protocol Feature → type declarations: Protocol declarations feature A feature request or implementation 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

2 participants