Skip to content

Commit

Permalink
REPL: make UndefVarError aware of imported modules (#55932)
Browse files Browse the repository at this point in the history
(cherry picked from commit fbb3e11)
  • Loading branch information
IanButterworth authored and KristofferC committed Oct 7, 2024
1 parent 359b9cc commit 4eae986
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions base/experimental.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ function show_error_hints(io, ex, args...)
for handler in hinters
try
@invokelatest handler(io, ex, args...)
catch err
catch
tn = typeof(handler).name
@error "Hint-handler $handler for $(typeof(ex)) in $(tn.module) caused an error"
@error "Hint-handler $handler for $(typeof(ex)) in $(tn.module) caused an error" exception=current_exceptions()
end
end
end
Expand Down
12 changes: 11 additions & 1 deletion stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,17 @@ end
function _UndefVarError_warnfor(io::IO, m::Module, var::Symbol)
Base.isbindingresolved(m, var) || return false
(Base.isexported(m, var) || Base.ispublic(m, var)) || return false
print(io, "\nHint: a global variable of this name also exists in $m.")
active_mod = Base.active_module()
print(io, "\nHint: ")
if isdefined(active_mod, Symbol(m))
print(io, "a global variable of this name also exists in $m.")
else
if Symbol(m) == var
print(io, "$m is loaded but not imported in the active module $active_mod.")
else
print(io, "a global variable of this name may be made accessible by importing $m in the current active module $active_mod")
end
end
return true
end

Expand Down

0 comments on commit 4eae986

Please sign in to comment.