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-41] Covariance does not work for functions with variadic arguments #42664

Open
swift-ci opened this issue Dec 4, 2015 · 2 comments
Open
Labels
compiler The Swift compiler itself feature A feature request or implementation

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Dec 4, 2015

Previous ID SR-41
Radar rdar://23011851
Original Reporter nikita (JIRA User)
Type Bug

Attachment: Download

Environment

Xcode 7.1.1 (7B1005)

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

md5: 1344eed40e3fc0135966b4277a47f007

relates to:

  • SR-27 Passing variadic function as a function parameter crashes compiler with SIGSEGV

Issue Description:

Swift 2.2 covariance unable to resolve functions covariance with variadic arguments.

Steps to Reproduce:
Attached a playground that shows the problem, as well as screenshot with errors. Here is a copy & paste of the code for your convenience:

func giveMeVoid(callback: (Void)->Void) {
    
}

func giveMeInt(callback: (Int)->Void) {
    
}

func any(values:Any?...) {
    
}

any()
any(5)

giveMeVoid(any) //This line will fail
giveMeInt(any) //This line will fail

Expected Results:
It is expected that `any` will be accepted by both giveMeVoid and giveMeInt functions, as they can work as `Void` and `Int` functions when they called directly.

Actual Results:
Non of functions accept 'any'. Following errors are thrown:

error: cannot convert value of type '(Any?...) -> ()' to expected argument type '(Void) -> Void'
error: cannot convert value of type '(Any?...) -> ()' to expected argument type '(Int) -> Void'
@CodaFi
Copy link
Contributor

CodaFi commented Jul 11, 2016

This is not a variance issue, this is an implicit coercion that you're asking for. We would need to add additional thunks to help with the wrapping here. @rjmccall how feasible is something like this?

@rjmccall
Copy link
Contributor

We're not really set up for it; the subtype-conversion logic really wants to translate specific arguments, not completely rework them structurally. It could be fixed, though.

This is an interesting idea, but I'm not sure we want to generalize function conversions to apply to literally anything where you could forward the arguments this way.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added new feature and removed bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. labels Jun 16, 2022
@AnthonyLatsis AnthonyLatsis added feature A feature request or implementation and removed new feature labels Jun 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler itself feature A feature request or implementation
Projects
None yet
Development

No branches or pull requests

4 participants