Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 7 additions & 1 deletion stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ function UndefVarError_hint(io::IO, ex::UndefVarError)
if C_NULL == owner
# No global of this name exists in this module.
# This is the common case, so do not print that information.
print(io, "\nSuggestion: check for spelling errors or missing imports.")
# It could be the binding was exported by two modules, which we can detect
# by the `usingfailed` flag in the binding:
if isdefined(bnd, :flags) && Bool(bnd.flags >> 4 & 1) # magic location of the `usingfailed` flag
print(io, "\nHint: It looks like this name was exported by two different modules, resulting in ambiguity. Try explicitly importing it, or qualifying the name with the module it should come from.")
else
print(io, "\nSuggestion: check for spelling errors or missing imports.")
end
owner = bnd
else
owner = unsafe_pointer_to_objref(owner)::Core.Binding
Expand Down
25 changes: 25 additions & 0 deletions stdlib/REPL/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1696,6 +1696,31 @@ finally
empty!(Base.Experimental._hint_handlers)
end

try # test the functionality of `UndefVarError_hint` against import clashes
@assert isempty(Base.Experimental._hint_handlers)
Base.Experimental.register_error_hint(REPL.UndefVarError_hint, UndefVarError)

@eval module X

module A
export x
x = 1
end # A

module B
export x
x = 2
end # B

using .A, .B

end # X

@test_throws "Hint: It looks like this name was exported by two different modules, resulting in ambiguity. Try explicitly importing it, or qualifying the name with the module it should come from." X.x
finally
empty!(Base.Experimental._hint_handlers)
end

# Hints for tab completes

fake_repl() do stdin_write, stdout_read, repl
Expand Down