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

Types on kwargs can lead to confusing situations #16490

Open
IainNZ opened this issue May 20, 2016 · 4 comments
Open

Types on kwargs can lead to confusing situations #16490

IainNZ opened this issue May 20, 2016 · 4 comments
Labels
error handling Handling of exceptions by Julia or the user keyword arguments f(x; keyword=arguments)

Comments

@IainNZ
Copy link
Member

IainNZ commented May 20, 2016

I just helped @evanfields boil down a more complex situation to the following:

function trigger(a, b; c::Float64 = a * b)
    return true
end

On Julia 0.4, with trigger(5, 10, c = 3) you get

ERROR: LoadError: TypeError: trigger: in typeassert, expected Float64, got Int64

Which I consider fairly understandable (unfortunate that you don't get told which field it was though).

With trigger(5, 10), again on 0.4, however, you get

ERROR: LoadError: MethodError: `__trigger#0__` has no method matching __trigger#0__(::Int64, ::Int64, ::Int64)
Closest candidates are:
  __trigger#0__(::Float64, ::Any, ::Any)

Which, while fairly understandable in retrospect, is totally baffling unless you know how kwargs are lowered. Its unfortunate that its a different error message though, for a similar sin. It is also hard to figure out whats going on in more complex cases - here it was a 2+1 arg function, but the original setting was much more interesting.

On Julia 0.5 you get

ERROR: LoadError: TypeError: #trigger: in typeassert, expected Float64, got Int64
 in (::#kw##trigger)(::Array{Any,1}, ::#trigger, ::Int64, ::Int64) at ./null:0

for the first, which is worse than 0.4 (the null:0 is delightful) , and for the second case you get

ERROR: LoadError: MethodError: no method matching #trigger#1(::Int64, ::#trigger, ::Int64, ::Int64)
Closest candidates are:
  #trigger#1(::Float64, ::Any, ::Any, ::Any)
 in trigger(::Int64, ::Int64) at /Users/idunning/....

which is even more exciting maybe.

Is there a path forward for making these messages nicer, or is too much information lost when lowering?

@IainNZ
Copy link
Member Author

IainNZ commented May 20, 2016

Related whining about error messages and kwargs in #15639

@tkelman tkelman added the error handling Handling of exceptions by Julia or the user label May 21, 2016
@andyferris
Copy link
Member

I agree all of this is very confusing, and has caught me in the past. +1 for fixing - assuming it isn't too hard (sorry I wouldn't know where to start).

@IainNZ
Copy link
Member Author

IainNZ commented Jun 2, 2018

Still a problem IMO (behaviour still same as in 0.5 I think), but very much post 1.0.

@ExpandingMan
Copy link
Contributor

ExpandingMan commented May 24, 2019

I just got burned by this, minimal example on Julia 1.1.1 as follows:

julia> const A = nothing

julia> f(;a::Int=A) = a
f (generic function with 1 method)

julia> f()
ERROR: MethodError: no method matching #f#7(::Nothing, ::typeof(f))
Closest candidates are:
  #f#7(::Int64, ::Any) at REPL[2]:1
Stacktrace:
 [1] f() at ./REPL[2]:1
 [2] top-level scope at none:0

It's a bit better than the old examples I see here, but it still took me quite a while to figure out what was going on when I encountered it in real code, and I dare say I have quite a lot of experience reading Julia stack traces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error handling Handling of exceptions by Julia or the user keyword arguments f(x; keyword=arguments)
Projects
None yet
Development

No branches or pull requests

5 participants