Skip to content

Commit 54598fa

Browse files
committed
minor refactors on REPLCompletions.jl
Those I found while working on #52952.
1 parent 3ed49fd commit 54598fa

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

stdlib/REPL/src/REPLCompletions.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ function complete_any_methods(ex_org::Expr, callee_module::Module, context_modul
812812
isa(c, TextCompletion) && return false
813813
isa(c, MethodCompletion) || return true
814814
sig = Base.unwrap_unionall(c.method.sig)::DataType
815-
return !all(T -> T === Any || T === Vararg{Any}, sig.parameters[2:end])
815+
return !all(@nospecialize(T) -> T === Any || T === Vararg{Any}, sig.parameters[2:end])
816816
end
817817
end
818818

@@ -1400,7 +1400,7 @@ function shell_completions(string, pos)
14001400
r = pos+1:pos
14011401
paths, dir, success = complete_path("", use_envpath=false, shell_escape=true)
14021402
return paths, r, success
1403-
elseif all(arg -> arg isa AbstractString, ex.args)
1403+
elseif all(@nospecialize(arg) -> arg isa AbstractString, ex.args)
14041404
# Join these and treat this as a path
14051405
path::String = join(ex.args)
14061406
r = last_arg_start:pos
@@ -1479,22 +1479,28 @@ function UndefVarError_hint(io::IO, ex::UndefVarError)
14791479
else
14801480
scope = undef
14811481
end
1482-
warnfor(m, var) = Base.isbindingresolved(m, var) && (Base.isexported(m, var) || Base.ispublic(m, var)) && (print(io, "\nHint: a global variable of this name also exists in $m."); true)
1483-
if scope !== Base && !warnfor(Base, var)
1482+
if scope !== Base && !_UndefVarError_warnfor(Base, var)
14841483
warned = false
14851484
for m in Base.loaded_modules_order
14861485
m === Core && continue
14871486
m === Base && continue
14881487
m === Main && continue
14891488
m === scope && continue
1490-
warned = warnfor(m, var) || warned
1489+
warned = _UndefVarError_warnfor(m, var) || warned
14911490
end
1492-
warned = warned || warnfor(Core, var)
1493-
warned = warned || warnfor(Main, var)
1491+
warned = warned || _UndefVarError_warnfor(Core, var)
1492+
warned = warned || _UndefVarError_warnfor(Main, var)
14941493
end
14951494
nothing
14961495
end
14971496

1497+
function _UndefVarError_warnfor(io::IO, m::Module, var::Symbol)
1498+
Base.isbindingresolved(m, var) || return false
1499+
(Base.isexported(m, var) || Base.ispublic(m, var)) || return false
1500+
print(io, "\nHint: a global variable of this name also exists in $m.")
1501+
return true
1502+
end
1503+
14981504
function __init__()
14991505
Base.Experimental.register_error_hint(UndefVarError_hint, UndefVarError)
15001506
COMPLETION_WORLD[] = Base.get_world_counter()

0 commit comments

Comments
 (0)