-
Notifications
You must be signed in to change notification settings - Fork 12.8k
fix #19220: polish arity error message #19405
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
fix #19220: polish arity error message #19405
Conversation
I would argue that this incorrect error is (1) rare (2) not that bad of an error message, and that this fix adds more complexity than it's worth. The bad error makes the compiler look silly, but it's not that confusing because it's so obviously incorrect. A quick look at the overload definitions will show which overloads exist -- and that quick look was always needed until recently. The pathological case is something like "1-5 arguments expected, but got 3." where only 1 and 5 parameter-overloads are defined, but nothing in between. But I expect this case to be vanishingly rare. The normal case just requires the user to change from 2 to 1 or 3. Even if we do decide that "1-3 arguments expected, but got 2." needs to be fixed, the fixed error should not replace errors like "1-2 arguments expected, but got 3" or "... but got 0". These errors are just as correct, are more compact, and convey more information. |
Fair argument. Should I close this pull request? |
No, I had a long discussion with @mhegazy and we decided that reporting ranges that include overloads is not that useful. Here's what I'd like to see:
Examples:
Note that @mhegazy and I discussed applying this technique to both overloads and optional/rest parameters. That is, give an elaboration for optional parameters as well: "Got 1 arguments, but no signature matched. \n At least 2 parameters are required." This would change error reporting considerably, so I'd have to see it decide if it's a good idea. And it's significantly more complicated to implement, so I think it would be better to try the above technique instead. In the meantime, I will:
|
Sorry for the late reply. But I'm afraid I am and will be quite busy these day. So I won't have time to refine this pull request. So let me close this and leave it for other contributors who are interested. Thank you! |
No problem; I have 2 other arity fixes that I need to work on, so I will start from this code when I do. Here's the summary for cross-referencing purposes:
|
Fix #19220 .
Only overloaded call without spread arguments has new error message. I also change the wording so the message seems more concise than that proposed in #19220. It's up to @DanielRosenwasser.
For single non-overloaded call, the original error message is better than the new one because it provides the range of acceptable argument number.
I cannot find a proper description for spread argument call. The message
No overload accepts {0} arguments
requires accurate argument number which isn't available in spread argument. So current error message is better IMHO.Finally, range of argument number in overload function call isn't provided. Showing that range is too complex to preserve a sensible error message.
Thanks for your review in advance!