Skip to content

Commit 3a63f25

Browse files
authored
fixup! JuliaLang#52953, follow up the refactor on REPLCompletions.jl (JuliaLang#52959)
1 parent 607b2b9 commit 3a63f25

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

stdlib/REPL/src/REPLCompletions.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,17 +1479,18 @@ function UndefVarError_hint(io::IO, ex::UndefVarError)
14791479
else
14801480
scope = undef
14811481
end
1482-
if scope !== Base && !_UndefVarError_warnfor(Base, var)
1482+
if scope !== Base && !_UndefVarError_warnfor(io, Base, var)
14831483
warned = false
14841484
for m in Base.loaded_modules_order
14851485
m === Core && continue
14861486
m === Base && continue
14871487
m === Main && continue
14881488
m === scope && continue
1489-
warned = _UndefVarError_warnfor(m, var) || warned
1489+
warned |= _UndefVarError_warnfor(io, m, var)
14901490
end
1491-
warned = warned || _UndefVarError_warnfor(Core, var)
1492-
warned = warned || _UndefVarError_warnfor(Main, var)
1491+
warned ||
1492+
_UndefVarError_warnfor(io, Core, var) ||
1493+
_UndefVarError_warnfor(io, Main, var)
14931494
end
14941495
nothing
14951496
end

stdlib/REPL/test/repl.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,27 @@ fake_repl() do stdin_write, stdout_read, repl
16751675
@test contains(txt, "Some type information was truncated. Use `show(err)` to see complete types.")
16761676
end
16771677

1678+
try # test the functionality of `UndefVarError_hint` against `Base.remove_linenums!`
1679+
@assert isempty(Base.Experimental._hint_handlers)
1680+
Base.Experimental.register_error_hint(REPL.REPLCompletions.UndefVarError_hint, UndefVarError)
1681+
1682+
# check the requirement to trigger the hint via `UndefVarError_hint`
1683+
@test !isdefined(Main, :remove_linenums!) && Base.ispublic(Base, :remove_linenums!)
1684+
1685+
fake_repl() do stdin_write, stdout_read, repl
1686+
backend = REPL.REPLBackend()
1687+
repltask = @async REPL.run_repl(repl; backend)
1688+
write(stdin_write,
1689+
"remove_linenums!\n\"ZZZZZ\"\n")
1690+
txt = readuntil(stdout_read, "ZZZZZ")
1691+
write(stdin_write, '\x04')
1692+
wait(repltask)
1693+
@test occursin("Hint: a global variable of this name also exists in Base.", txt)
1694+
end
1695+
finally
1696+
empty!(Base.Experimental._hint_handlers)
1697+
end
1698+
16781699
# Hints for tab completes
16791700

16801701
fake_repl() do stdin_write, stdout_read, repl

0 commit comments

Comments
 (0)