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-14201] type checker ambiguity regarding return values. #56579
Comments
@swift-ci create |
Interestingly both cases bellow type checks correctly ... func test() -> Future<Void> {
return self.then { value in
self.returnFuture()
}.then { value in
return self.returnFuture()
}.then { value -> Int in
if value > 4 {
throw E()
} else {
return 8
}
}.then { value in
return ()
}
}
func test() -> Future<Void> {
return self.then { value in
self.returnFuture()
}.then { value in
return self.returnFuture()
}.then { value in
return 8
}.then { value in
return ()
}
} so this can maybe indicate that the issue maybe related to how contextual information is propagated from the previous closure in this case... |
Unfortunately this is just a consequence multi-statement closure bodies not participating in the type-check (which was a deliberate decision at the time due to performance), so there is no way for the solver to pick a "right" overload for one-before-last `then` since there is no way to tell what type the body is going to produce unless it's actually type-checker together with enclosing context. |
@xedin I wonder if we could keep this open/or maybe open another to improve diagnostics? func test() -> Future<Void> {
return self.then { value in
self.returnFuture()
}.then { value in
return self.returnFuture()
}.then { value in // error: Unable to infer complex closure return type; add explicit type to disambiguate
if value > 4 {
throw E()
} else {
return 8
}
}.then { value -> Void in
return ()
}
} |
@xedin I also think we should keep this open. It’s a deficiency of the current algorithm that we decided not to fix right now which is unfortunate but understandable. Would you agree with this? |
Let's just dupe it to one of the open ones in the list https://bugs.swift.org/browse/SR-2033?jql=text%20~%20%22multi-statement%22. SR-2033 IMO is the closest one here since it's the same problem where an incorrect choice gets picked up and incorrectly diagnosed. |
It'd be great to organize these a bit too instead of keeping so many duplicates open :/ |
Environment
swift main, 9th Feb 2021
Additional Detail from JIRA
md5: ec593532406ed584d7e1d52315258d4c
Issue Description:
Consider this program which compiles
if at the very bottom, I change {{ (value: Int) -> Void }} to {{ value -> Void }}, then the compiler can no longer resolve the ambiguity and complains
but I believe that should work.
The failing program
The text was updated successfully, but these errors were encountered: