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

Always show "closest candidates" when there is a MethodError #46236

Closed
nickrobinson251 opened this issue Aug 1, 2022 · 0 comments · Fixed by #53165
Closed

Always show "closest candidates" when there is a MethodError #46236

nickrobinson251 opened this issue Aug 1, 2022 · 0 comments · Fixed by #53165
Labels
error messages Better, more actionable error messages

Comments

@nickrobinson251
Copy link
Contributor

Currently we have heuristics for building a list of "closest candidate" methods to display when a user hits a MethodError, but these heuristics can result in no methods making the list... so we show none of the valid methods which seems less helpful than showing some (/any) of the valid methods.

For example, this seems to happens if none of the argument types match and more than two arguments were given.

julia> foo(x::Int, y::Int, z=1, a=2) = 1;

julia> foo("a")  
ERROR: MethodError: no method matching foo(::String)
Closest candidates are:
  foo(::Int64, ::Int64) at REPL[1]:1
  foo(::Int64, ::Int64, ::Any) at REPL[1]:1
  foo(::Int64, ::Int64, ::Any, ::Any) at REPL[1]:1
Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

julia> foo("a", "b")  # why no "Closest candidates"?
ERROR: MethodError: no method matching foo(::String, ::String)
Stacktrace:
 [1] top-level scope
   @ REPL[3]:1

if right_matches > 0 || length(arg_types_param) < 2

I don't know why this heuristic was chosen, and I think we should remove such heuristics that discard methods. We can still show only 3 candidates and ordered by some measure of "closeness", but showing some methods seems strictly more informative than showing none.

very related to #32470 (but i've opened this separately as this is a more narrow request and that one seem to have become about how to print this information in a good way, rather than which methods to print)

@nickrobinson251 nickrobinson251 changed the title Always show "closest candidate" when there is a MethodError Always show "closest candidates" when there is a MethodError Aug 1, 2022
@kshyatt kshyatt added the error messages Better, more actionable error messages label Oct 5, 2022
vtjnash added a commit that referenced this issue Feb 3, 2024
Updated version of #33793. Always show up to 3 methods, even if no
arguments types match on some of them, but rank ones with fewer
arguments before those with more arguments.

Closes #33793
Fixes #33793
Fixes #46236
Co-authored-by: Eric Wright <efwright@udel.edu>
vtjnash added a commit that referenced this issue Feb 10, 2024
Updated version of #33793. Always show up to 3 methods, even if no
arguments types match on some of them, but rank ones with fewer
arguments before those with more arguments.

Closes #33793
Fixes #33793
Fixes #46236
Co-authored-by: Eric Wright <efwright@udel.edu>
(this diff best viewed with whitespace ignored)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error messages Better, more actionable error messages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants