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

Confusing MethodError message #228

Closed
knuesel opened this issue May 15, 2020 · 4 comments
Closed

Confusing MethodError message #228

knuesel opened this issue May 15, 2020 · 4 comments

Comments

@knuesel
Copy link

knuesel commented May 15, 2020

The error shown by zeta for unsupported number types is confusing:

julia> using Measurements

julia> zeta(2.0 ± 0.1)
ERROR: MethodError: no method matching zeta(::Measurement{Float64})
Closest candidates are:
  zeta(::Number) at /home/user/.julia/packages/SpecialFunctions/Bdhxh/src/gamma.jl:527
  zeta(::Number, ::Number) at /home/user/.julia/packages/SpecialFunctions/Bdhxh/src/gamma.jl:547
  zeta(::BigFloat) at /home/user/.julia/packages/SpecialFunctions/Bdhxh/src/gamma.jl:465
  ...

It's confusing since there is a candidate zeta(::Number) and

julia> Measurement{Float64} <: Number
true
@giordano
Copy link
Member

giordano commented May 15, 2020

Well, the method you mentioned throws a MethodError:

function $f(z::Number)
x = float(z)
typeof(x) === typeof(z) && throw(MethodError($f, (z,)))
# There is nothing to fallback to, as this didn't change the argument types
$f(x)
end

The case of the zeta function is explicitly mentioned in the documentation of Measurements.jl:

julia> using Measurements, SpecialFunctions

julia> @uncertain zeta(2.0 ± 0.1)
1.645 ± 0.094

@knuesel
Copy link
Author

knuesel commented May 15, 2020

Indeed... Maybe it should throw an ArgumentError instead, with an informative message? Or maybe it's an issue with MethodError itself (discussion on Discourse).

@devmotion
Copy link
Member

The confusing MethodError was fixed by #347. Instead of throwing a MethodError manually now zeta(::Number) calls an internal function SpecialFunctions._zeta which uses regular dispatching. With SpecialFunctions 1.7.0:

julia> using Measurements, SpecialFunctions

julia> zeta(2.0 ± 0.1)
ERROR: MethodError: no method matching _zeta(::Measurement{Float64})
Closest candidates are:
  _zeta(::Union{Float64, ComplexF64}) at /home/david/.julia/packages/SpecialFunctions/5CocL/src/gamma.jl:414
  _zeta(::T, ::T) where T<:Union{Float64, ComplexF64} at /home/david/.julia/packages/SpecialFunctions/5CocL/src/gamma.jl:233
  _zeta(::BigFloat) at /home/david/.julia/packages/SpecialFunctions/5CocL/src/gamma.jl:473
  ...
Stacktrace:
 [1] zeta(s::Measurement{Float64})
   @ SpecialFunctions ~/.julia/packages/SpecialFunctions/5CocL/src/gamma.jl:412
 [2] top-level scope
   @ REPL[4]:1

@knuesel knuesel closed this as completed Sep 29, 2021
@knuesel
Copy link
Author

knuesel commented Sep 29, 2021

Indeed that fixes it, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants