Skip to content

Commit

Permalink
errorshow: Show hint when + is attempted on AbstractStrings
Browse files Browse the repository at this point in the history
  • Loading branch information
merryhime committed Jul 10, 2022
1 parent 545bec0 commit cb1c867
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,22 @@ end

Experimental.register_error_hint(noncallable_number_hint_handler, MethodError)

# Display a hint in case the user tries to call the instance of a number
# (probably missing the operator)
# eg: (1 + 2)(3 + 4)
# Display a hint in case the user tries to use the + operator on strings
# (probably attempting concatenation)
function string_concatenation_hint_handler(io, ex, arg_types, kwargs)
@nospecialize
if (ex.f == +) && all(i -> i <: AbstractString, arg_types)
print(io, "\nString concatenation is performed with ")
printstyled(io, "*", color=:cyan)
print(io, " (See also: https://docs.julialang.org/en/v1/manual/strings/#man-concatenation).")
end
end

Experimental.register_error_hint(string_concatenation_hint_handler, MethodError)

# ExceptionStack implementation
size(s::ExceptionStack) = size(s.stack)
getindex(s::ExceptionStack, i::Int) = s.stack[i]
Expand Down

0 comments on commit cb1c867

Please sign in to comment.