Skip to content

Commit

Permalink
Added so !Matched is printed in front of a type that is not matched…
Browse files Browse the repository at this point in the history
… when `have_color=false`
  • Loading branch information
dhoegh committed Jan 17, 2015
1 parent b015a9d commit 4c13083
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
14 changes: 9 additions & 5 deletions base/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,15 @@ function show_method_candidates(io::IO, ex::MethodError)
# checks if the type of arg 1:i of the input intersects with the current method
t_in = typeintersect(method.sig[1:i], tuple(t_i[1:j]...))
if t_in == None
if Base.have_color
print(buf, "\e[1m\e[31m::$(method.sig[i])\e[0m")
else
print(buf, "!Matched::$(method.sig[i])")
end
# If there is no typeintersect then the type signature from the method is
# inserted in t_i this ensures if the type at the next i matches the type
# signature then there will be a type intersect
t_i[i] = method.sig[i]
Base.with_output_color(:red, buf) do buf
print(buf, "::$(method.sig[i])")
end
else
right_matches += j==i ? 1 : 0
print(buf, "::$(method.sig[i])")
Expand All @@ -221,8 +223,10 @@ function show_method_candidates(io::IO, ex::MethodError)
# arguments is printed as not a match
for sigtype in method.sig[length(t_i)+1:end]
print(buf, ", ")
Base.with_output_color(:red, buf) do buf
print(buf, "::$(sigtype)")
if Base.have_color
print(buf, "\e[1m\e[31m::$sigtype\e[0m")
else
print(buf, "!Matched::$sigtype")
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions test/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ method_c1(x::Float64, s::AbstractString...) = true

buf = IOBuffer()
Base.show_method_candidates(buf, Base.MethodError(method_c1,(1, 1, "")))
no_color = "\nClosest candidates are:\n method_c1(::Float64, ::AbstractString...)\n"
no_color = "\nClosest candidates are:\n method_c1(!Matched::Float64, !Matched::AbstractString...)\n"
test_have_color(buf,
"\e[0m\nClosest candidates are:\n method_c1(\e[1m\e[31m::Float64\e[0m, \e[1m\e[31m::AbstractString...\e[0m)\n\e[0m",
no_color)

no_color = "\nClosest candidates are:\n method_c1(!Matched::Float64, ::AbstractString...)\n"
Base.show_method_candidates(buf, Base.MethodError(method_c1,(1, "", "")))
test_have_color(buf,
"\e[0m\nClosest candidates are:\n method_c1(\e[1m\e[31m::Float64\e[0m, ::AbstractString...)\n\e[0m",
Expand All @@ -37,5 +38,5 @@ method_c2{T<:Real}(x::T, y::T, z::T) = true

Base.show_method_candidates(buf, Base.MethodError(method_c2,(1., 1., 2)))
color = "\e[0m\nClosest candidates are:\n method_c2(\e[1m\e[31m::Int32\e[0m, ::Float64, ::Any...)\n method_c2(\e[1m\e[31m::Int32\e[0m, ::Any...)\n method_c2{T<:Real}(::T<:Real, ::T<:Real, \e[1m\e[31m::T<:Real\e[0m)\n ...\n\e[0m"
no_color = no_color = "\nClosest candidates are:\n method_c2(::Int32, ::Float64, ::Any...)\n method_c2(::Int32, ::Any...)\n method_c2{T<:Real}(::T<:Real, ::T<:Real, ::T<:Real)\n ...\n"
no_color = no_color = "\nClosest candidates are:\n method_c2(!Matched::Int32, ::Float64, ::Any...)\n method_c2(!Matched::Int32, ::Any...)\n method_c2{T<:Real}(::T<:Real, ::T<:Real, !Matched::T<:Real)\n ...\n"
test_have_color(buf, color, no_color)

0 comments on commit 4c13083

Please sign in to comment.