-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Closure Evaluation Misdiagnoses Initializer Type Checking #62051
Comments
Reduction for the first example: struct Foo {
init(_: Bool) {}
}
func foo(_: () -> Foo?) {}
//let _: () -> Foo? = { // Correct diagnostic
foo {
if true {
return nil
}
return Foo(0)
} |
I'll take a look! |
@xedin I've looked at this issue, and there seems to be an issue with the constraint solver. If we take the code @AnthonyLatsis provided and further simplify it like so, func foo(_: () -> Bool?) {}
// let _: () -> Bool? = { // Correct diagnostic
foo {
if true {
return nil
}
return 0
} we can then print out all the solutions that the constraint solver found. In both scenarios, the correct solution is found with value 3. But in the incorrect case, the solver finds another winning solution with value 1 that looks like this: |
You can anchor your search on this lines in the debug output:
This is where solving for First solver binding contextual (result) type to To fix this issue we need to to make sure that the original fix where contextual type is |
@xedin I am trying to wrap my head around this so I can help Sima. Do you mind talking this out with me? So there are 2 solutions we end up with in diagnostics (salvage) mode. Here is an overview of the debug output with a focus on fixes:
I assume we can get away with increasing the impact of the contextual mismatch with the |
Describe the bug
When using a generic initializer of a type that is returned in a
compactMap
closure, the compiler gives misleading errors as part of the closure evaluation.Steps To Reproduce
I found two separate reproduction cases that give two different errors
First Reproduction
Second Reproduction
Expected behavior
The compiler to correctly diagnose the type mismatch on the initializer:
Cannot convert value of type '[Int]' to expected argument type '[Bool]'
Screenshots
N/A
Environment (please fill out the following information)
Additional context
N/A
The text was updated successfully, but these errors were encountered: