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-8797] Misleading compiler errors #51305

Open
jeremyabannister opened this issue Sep 19, 2018 · 7 comments
Open

[SR-8797] Misleading compiler errors #51305

jeremyabannister opened this issue Sep 19, 2018 · 7 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers type checker Area → compiler: Semantic analysis

Comments

@jeremyabannister
Copy link

Previous ID SR-8797
Radar rdar://problem/44616337
Original Reporter @jeremyabannister
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, StarterBug, TypeChecker
Assignee None
Priority Medium

md5: f2dc6c9ca2ac0b74c004d15fc50e5a7b

Issue Description:

typealias Executable <Input> = (Input)->()
let test: Executable<Void>? = { }

The code above leads to the error:

Cannot convert value of type '() -> ()' to specified type '((Void) -> ())?'

Whereas this code compiles successfully:

typealias Executable <Input> = (Input)->()
let test: Executable<Void>? = { _ in }
@belkadan
Copy link
Contributor

That sounds correct to me. A function that takes one argument is different from a function that takes zero arguments, even when that one argument is Void (the empty tuple). What diagnostic would you have preferred?

@belkadan
Copy link
Contributor

cc @rudkx

@rudkx
Copy link
Member

rudkx commented Sep 19, 2018

Yes this is expected behavior at this point.

I floated a pitch at one point to fix this because it makes it difficult to write generic code that composes well in some cases, but there was little to no enthusiasm for doing anything about it and I haven't had time to pursue it since.

@rudkx
Copy link
Member

rudkx commented Sep 19, 2018

@xedin, perhaps we could have a better diagnostic here to make it more clear what the issue is?

@xedin
Copy link
Member

xedin commented Sep 19, 2018

Yes, I think it makes sense to say that it expected on argument not got 0 or something similar...

@xedin
Copy link
Member

xedin commented Sep 19, 2018

@swift-ci create

@jeremyabannister
Copy link
Author

@belkadan @rudkx @xedin

Thanks for the speedy responses guys - I realize now that the error is perfectly fine, this was just a gap in my understanding of `Void`. What I wish is that there were a way to use my `Executable<Input>` typealias to represent `()->()`. Given the fact that there is only one possible value of `Void` it does feel to me that the need for that input qualifies as boilerplate code, but I can understand that introducing the idea of treating a function type with no arguments as being equivalent to a function type with one (trivial) argument might be very unsound.

@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 diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants