Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL: make UndefVarError aware of imported modules #55932

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/experimental.jl
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ function show_error_hints(io, ex, args...)
@invokelatest handler(io, ex, args...)
catch err
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" err
IanButterworth marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
Expand Down
13 changes: 12 additions & 1 deletion stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,18 @@ 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()
mod_imported = isdefined(active_mod, Symbol(m))
if !mod_imported && Symbol(m) == var
print(io, "\nHint: $m is loaded but not imported in the active module `$(active_mod)`.")
else
print(io, "\nHint: a global variable of this name also exists in $m")
if mod_imported
print(io, ".")
else
print(io, ", which is loaded but not imported in the active module `$(active_mod)`.")
end
end
return true
end

Expand Down