You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Evidently, this function with four parameters is seen by the compiler as "fitting" the declaration with just one generic parameter.
I'm not going to try to conjecture why that is. Okay, I'll conjecture: it might have something to do with the legacy of parameter lists as tuples. But I still see it as a bug, because even though this compiles and runs as it stands, I cannot find a way, inside `doSomething`, to call the function `function` that was passed in. It is typed as taking one parameter, and I can't find a parameter type that will satisfy the compiler:
Okay, so I tested with the May 4 2020 Swift 5.3 Development toolchain, and sure enough, we now compile with all four variants of the `doSomething` method present.
If we remove all but the first (one parameter) version of `doSomething`, we still compile and that method is called. If we express the four `function` parameters as a single tuple and force cast with `as! T`, the `function` is called correctly.
So if that is acceptable behavior, the bug is fixed. I find that last bit a little surprising, but it's nothing one can't live with; the key point is that, faced with a choice of all four, the compiler picks the four-parameter version of `doSomething`, which is the expected behavior in the larger sense.
Additional Detail from JIRA
md5: b58ab3c757b250eadaa7853953acb03c
duplicates:
Issue Description:
This compiles and works as expected:
But if you add a version with one passed function parameter, everything breaks down:
Now we can't compile, because the first version is seen as a candidate. And indeed, if we remove the other versions, we still compile!
Evidently, this function with four parameters is seen by the compiler as "fitting" the declaration with just one generic parameter.
I'm not going to try to conjecture why that is. Okay, I'll conjecture: it might have something to do with the legacy of parameter lists as tuples. But I still see it as a bug, because even though this compiles and runs as it stands, I cannot find a way, inside `doSomething`, to call the function `function` that was passed in. It is typed as taking one parameter, and I can't find a parameter type that will satisfy the compiler:
So I regard it as a bug that the one-generic version of `doSomething` is seen by the compiler as satisfied by passing the four-parameter function `f`.
The text was updated successfully, but these errors were encountered: