diff --git a/base/replutil.jl b/base/replutil.jl index 48517a906dd835..7852827f33de1e 100644 --- a/base/replutil.jl +++ b/base/replutil.jl @@ -130,7 +130,7 @@ function showerror(io::IO, ex::MethodError) name = ft.name.mt.name arg_types_param = arg_types_param[3:end] temp = ex.args[1] - kwargs = [(temp[i*2-1], temp[i*2]) for i in 1:(length(temp) ÷ 2)] + kwargs = Any[(temp[i*2-1], temp[i*2]) for i in 1:(length(temp) ÷ 2)] ex = MethodError(f, ex.args[3:end]) end if f == Base.convert && length(arg_types_param) == 2 && !is_arg_types @@ -163,7 +163,8 @@ function showerror(io::IO, ex::MethodError) if !isempty(kwargs) print(io, "; ") for (i ,(k, v)) in enumerate(kwargs) - print(io, k, "=", v) + print(io, k, "=") + show(IOContext(io, :limit=>true), v) i == length(kwargs) || print(io, ", ") end end @@ -239,7 +240,7 @@ function showerror_nostdio(err, msg::AbstractString) ccall(:jl_printf, Cint, (Ptr{Void},Cstring), stderr_stream, "\n") end -function show_method_candidates(io::IO, ex::MethodError, kwargs=Tuple{Symbol, Any}[]) +function show_method_candidates(io::IO, ex::MethodError, kwargs::Vector=Any[]) is_arg_types = isa(ex.args, DataType) arg_types = is_arg_types ? ex.args : typesof(ex.args...) arg_types_param = Any[arg_types.parameters...] diff --git a/test/replutil.jl b/test/replutil.jl index fc1c624150d679..321a379db807c4 100644 --- a/test/replutil.jl +++ b/test/replutil.jl @@ -109,6 +109,10 @@ method_c7(a, b; kargs...) = a Base.show_method_candidates(buf, MethodError(method_c7, (1, 1)), [(:x, 1), (:y, 2)]) test_have_color(buf, "\e[0m\nClosest candidates are:\n method_c7(::Any, ::Any; kargs...)\e[0m", "\nClosest candidates are:\n method_c7(::Any, ::Any; kargs...)") +method_c8(a, b; y=1, w=1) = a +Base.show_method_candidates(buf, MethodError(method_c8, (1, 1)), [(:x, 1), (:y, 2), (:z, 1), (:w, 1)]) +test_have_color(buf, "\e[0m\nClosest candidates are:\n method_c8(::Any, ::Any; y, w)\e[1m\e[31m got an unsupported keyword argument \"x\", \"z\"\e[0m\e[0m", + "\nClosest candidates are:\n method_c8(::Any, ::Any; y, w) got an unsupported keyword argument \"x\", \"z\"") addConstraint_15639(c::Int32) = c addConstraint_15639(c::Int64; uncset=nothing) = addConstraint_15639(Int32(c), uncset=uncset)