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-4075] Array covariance does not apply to function subtyping #46658

Open
swift-ci opened this issue Feb 25, 2017 · 3 comments
Open

[SR-4075] Array covariance does not apply to function subtyping #46658

swift-ci opened this issue Feb 25, 2017 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-4075
Radar None
Original Reporter mroi (JIRA User)
Type Bug
Environment
Michael@jupiter:~ > swiftc --version
Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
Target: x86_64-apple-macosx10.9
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: f83b18da5d48933c1170230c46a5db8d

Issue Description:

class Super {}; class Sub: Super {}
func f(_: [Super]) {}
let test: ([Sub]) -> Void = f

Since functions are contravariant in their arguments and arrays are covariant in their element type, I would expect the assignment to work. However, it does not:

<stdin>:3:29: error: cannot convert value of type '([Super]) -> ()' to specified type '([Sub]) -> Void'
@CodaFi
Copy link
Member

CodaFi commented Feb 25, 2017

Arrays are invariant but we privilege certain array element upcasts.

@swift-ci
Copy link
Collaborator Author

Comment by Michael Roitzsch (JIRA)

Oh, sorry, I am not aware of such details. Please advise if I should change the title of this issue.

@belkadan
Copy link
Contributor

There's no reason why this couldn't work. Once we added the general array-of-concrete-type-to-array-of-protocol-type conversion we already gave up on trying to distinguish these cases. We should be able to treat array element upcasts like any other conversion.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants