Skip to content

Commit 4eae986

Browse files
IanButterworthKristofferC
authored andcommitted
REPL: make UndefVarError aware of imported modules (#55932)
(cherry picked from commit fbb3e11)
1 parent 359b9cc commit 4eae986

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

base/experimental.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ function show_error_hints(io, ex, args...)
319319
for handler in hinters
320320
try
321321
@invokelatest handler(io, ex, args...)
322-
catch err
322+
catch
323323
tn = typeof(handler).name
324-
@error "Hint-handler $handler for $(typeof(ex)) in $(tn.module) caused an error"
324+
@error "Hint-handler $handler for $(typeof(ex)) in $(tn.module) caused an error" exception=current_exceptions()
325325
end
326326
end
327327
end

stdlib/REPL/src/REPL.jl

+11-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,17 @@ end
8181
function _UndefVarError_warnfor(io::IO, m::Module, var::Symbol)
8282
Base.isbindingresolved(m, var) || return false
8383
(Base.isexported(m, var) || Base.ispublic(m, var)) || return false
84-
print(io, "\nHint: a global variable of this name also exists in $m.")
84+
active_mod = Base.active_module()
85+
print(io, "\nHint: ")
86+
if isdefined(active_mod, Symbol(m))
87+
print(io, "a global variable of this name also exists in $m.")
88+
else
89+
if Symbol(m) == var
90+
print(io, "$m is loaded but not imported in the active module $active_mod.")
91+
else
92+
print(io, "a global variable of this name may be made accessible by importing $m in the current active module $active_mod")
93+
end
94+
end
8595
return true
8696
end
8797

0 commit comments

Comments
 (0)