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

which should give better error on ambiguous method #47322

Closed
LilithHafner opened this issue Oct 25, 2022 · 0 comments · Fixed by #47369
Closed

which should give better error on ambiguous method #47322

LilithHafner opened this issue Oct 25, 2022 · 0 comments · Fixed by #47369
Labels
error messages Better, more actionable error messages

Comments

@LilithHafner
Copy link
Member

Calling an ambiguous method gives a nice error message. Calling which on it does not:

julia> f(a::Int, b) = a+b
f (generic function with 1 method)

julia> f(a, b::Int) = a-b
f (generic function with 2 methods)

julia> f(2,2) # very helpful error message
ERROR: MethodError: f(::Int64, ::Int64) is ambiguous.

Candidates:
  f(a::Int64, b)
    @ Main REPL[21]:1
  f(a, b::Int64)
    @ Main REPL[22]:1

Possible fix, define
  f(::Int64, ::Int64)

Stacktrace:
 [1] top-level scope
   @ REPL[23]:1

julia> which(f, Tuple{Int,Int}) # less helpful error message
ERROR: no unique matching method found for the specified argument types
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] _which
   @ ./reflection.jl:1491 [inlined]
 [3] _which
   @ ./reflection.jl:1489 [inlined]
 [4] which(tt::Any)
   @ Base ./reflection.jl:1517
 [5] which(f::Any, t::Any)
   @ Base ./reflection.jl:1508
 [6] top-level scope
   @ REPL[24]:1

From #22988.

@LilithHafner LilithHafner added the error messages Better, more actionable error messages label Oct 25, 2022
apaz-cli added a commit to apaz-cli/julia that referenced this issue Oct 27, 2022
Error messages for `MethodError` are much more helpful
in determining why the method was not successfully dispatched
than simply "No unique matching method found."

Fixes JuliaLang#47322
apaz-cli added a commit to apaz-cli/julia that referenced this issue Oct 28, 2022
Error messages for `MethodError` are much more helpful
in determining why the method was not successfully dispatched
than simply "No unique matching method found."

Fixes JuliaLang#47322
maleadt pushed a commit to apaz-cli/julia that referenced this issue Nov 18, 2022
Error messages for `MethodError` are much more helpful
in determining why the method was not successfully dispatched
than simply "No unique matching method found."

Fixes JuliaLang#47322
vtjnash pushed a commit that referenced this issue Feb 1, 2024
The `MethodError` printing has detailed text on what failed about this
dispatch, which can be useful to someone trying to understand why
`which` failed, given that `which` is simply a model of the dispatch
done by `invoke`. Reuse that printing, but add a short custom header to
it and convert to an ErrorException, per triage discussion that this
would be clearest. Also add more text to `MethodError` to guide new
users in interpreting the exact meaning of some of the cryptic text.

Fixes #47322
vtjnash pushed a commit to apaz-cli/julia that referenced this issue Feb 1, 2024
The `MethodError` printing has detailed text on what failed about this
dispatch, which can be useful to someone trying to understand why
`which` failed, given that `which` is simply a model of the dispatch
done by `invoke`. Reuse that printing, but add a short custom header to
it and convert to an ErrorException, per triage discussion that this
would be clearest. Also add more text to `MethodError` to guide new
users in interpreting the exact meaning of some of the cryptic text.

Fixes JuliaLang#47322
vtjnash pushed a commit that referenced this issue Feb 3, 2024
Error messages for `MethodError` are much more helpful in determining
why the method was not successfully dispatched than simply "No unique
matching method found."

Fixes #47322
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.

1 participant