Skip to content

Commit 051be13

Browse files
Fix error hint for missing(1) (#58250)
Before: ```julia-repl julia> missing(1) ERROR: MethodError: objects of type Missing are not callable. In case you did not try calling it explicitly, check if a Missing has been passed as an argument to a method that expects a callable instead. The object of type `Missing` exists, but no method is defined for this combination of argument types when trying to treat it as a callable object.┌ Error: Hint-handler nonsetable_type_hint_handler for MethodError in Base caused an error │ exception = │ 1-element ExceptionStack: │ TypeError: non-boolean (Missing) used in boolean context │ Stacktrace: │ [1] nonsetable_type_hint_handler(io::Any, ex::Any, arg_types::Any, kwargs::Any) │ @ Base ./errorshow.jl:1054 │ [2] show_error_hints(::IOContext{Base.TTY}, ::MethodError, ::Vector{Any}, ::Vararg{Vector{Any}}) │ @ Base.Experimental ./experimental.jl:322 │ [3] showerror(io::IO, ex::MethodError) │ @ Base ./errorshow.jl:374 │ [4] showerror(io::IOContext{Base.TTY}, ex::MethodError, bt::Vector{Base.StackTraces.StackFrame}; backtrace::Bool) │ @ Base ./errorshow.jl:106 │ [5] show_exception_stack(io::IOContext{Base.TTY}, stack::Base.ExceptionStack) │ @ Base ./errorshow.jl:1017 │ [6] display_error(io::IOContext{Base.TTY}, stack::Base.ExceptionStack) │ @ Base ./client.jl:117 │ [7] repl_display_error(errio::IO, errval::Any) │ @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.13/REPL/src/REPL.jl:565 │ [8] print_response(errio::IO, response::Any, backend::Union{Nothing, REPL.REPLBackendRef}, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay}) │ @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.13/REPL/src/REPL.jl:582 │ [9] (::REPL.var"#print_response##0#print_response##1"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any) │ @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.13/REPL/src/REPL.jl:556 │ [10] with_repl_linfo(f::Any, repl::REPL.LineEditREPL) │ @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.13/REPL/src/REPL.jl:829 │ [11] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool) │ @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.13/REPL/src/REPL.jl:554 │ [12] (::REPL.var"#do_respond#73"{Bool, Bool, REPL.var"#setup_interface##12#setup_interface##13"{REPL.LineEditREPL, REPL.REPLHistoryProvider}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool) │ @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.13/REPL/src/REPL.jl:1186 │ [13] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState) │ @ REPL.LineEdit ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.13/REPL/src/LineEdit.jl:2852 │ [14] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef) │ @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.13/REPL/src/REPL.jl:1657 │ [15] (::REPL.var"#61#62"{REPL.LineEditREPL, REPL.REPLBackendRef})() │ @ REPL ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.13/REPL/src/REPL.jl:648 └ @ Base.Experimental experimental.jl:325 Stacktrace: [1] top-level scope @ REPL[1]:1 ``` After: ```julia-repl julia> missing(1) ERROR: MethodError: objects of type Missing are not callable. In case you did not try calling it explicitly, check if a Missing has been passed as an argument to a method that expects a callable instead. The object of type `Missing` exists, but no method is defined for this combination of argument types when trying to treat it as a callable object. Stacktrace: [1] top-level scope @ REPL[3]:1 ``` --------- Co-authored-by: Ian Butterworth <i.r.butterworth@gmail.com>
1 parent 13a142d commit 051be13

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

base/errorshow.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ Experimental.register_error_hint(noncallable_number_hint_handler, MethodError)
10561056
# eg: d = Dict; d["key"] = 2
10571057
function nonsetable_type_hint_handler(io, ex, arg_types, kwargs)
10581058
@nospecialize
1059-
if ex.f == setindex!
1059+
if ex.f === setindex!
10601060
T = arg_types[1]
10611061
if T <: Number
10621062
print(io, "\nAre you trying to index into an array? For multi-dimensional arrays, separate the indices with commas: ")

test/errorshow.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ let err_str,
406406
@test occursin("MethodError: no method matching Bool()", err_str)
407407
err_str = @except_str :a() MethodError
408408
@test occursin("MethodError: objects of type Symbol are not callable", err_str)
409+
err_str = @except_str missing(1) MethodError
410+
@test occursin("MethodError: objects of type Missing are not callable", err_str)
409411
err_str = @except_str EightBitType() MethodError
410412
@test occursin("MethodError: no method matching $(curmod_prefix)EightBitType()", err_str)
411413
err_str = @except_str i() MethodError

0 commit comments

Comments
 (0)