diff --git a/base/replutil.jl b/base/replutil.jl index c762a6da63466..820e3c82ef332 100644 --- a/base/replutil.jl +++ b/base/replutil.jl @@ -212,7 +212,7 @@ function show_method_candidates(io::IO, ex::MethodError) print(buf, "::$(method.sig[i])") end end - if length(t_i) > length(method.sig) && Base.isvarargtype(method.sig[end]) + if length(t_i) > length(method.sig) && !isempty(method.sig) && Base.isvarargtype(method.sig[end]) # It ensures that methods like f(a::AbstractString...) gets the correct # number of right_matches for t in typeof(ex.args)[length(method.sig):end] diff --git a/test/replutil.jl b/test/replutil.jl index ba4dcc3e04fe0..ad17a7885cc25 100644 --- a/test/replutil.jl +++ b/test/replutil.jl @@ -46,4 +46,8 @@ method_c3(x::Float64, y::Float64) = true Base.show_method_candidates(buf, Base.MethodError(method_c3,(1.,))) color = "\e[0m\nClosest candidates are:\n method_c3(::Float64, \e[1m\e[31m::Float64\e[0m)\n\e[0m" no_color = no_color = "\nClosest candidates are:\n method_c3(::Float64, !Matched::Float64)\n" -test_have_color(buf, color, no_color) \ No newline at end of file +test_have_color(buf, color, no_color) + +# Test for the method error in issue #8651 +Base.show_method_candidates(buf, MethodError(readline,(ASCIIString,))) +test_have_color(buf, "", "") \ No newline at end of file