From 26ceebfc0f941f17c8d5dde8fe1f91fb893560cb Mon Sep 17 00:00:00 2001 From: Lilith Orion Hafner Date: Sun, 17 Sep 2023 07:25:50 -0500 Subject: [PATCH] Don't give public but unexported symbols as repl completions in an unqualified context (#51345) --- stdlib/REPL/src/REPLCompletions.jl | 1 + stdlib/REPL/test/replcompletions.jl | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/stdlib/REPL/src/REPLCompletions.jl b/stdlib/REPL/src/REPLCompletions.jl index 8ceed06d1c5df..57ee508cd302b 100644 --- a/stdlib/REPL/src/REPLCompletions.jl +++ b/stdlib/REPL/src/REPLCompletions.jl @@ -136,6 +136,7 @@ end function filtered_mod_names(ffunc::Function, mod::Module, name::AbstractString, all::Bool = false, imported::Bool = false) ssyms = names(mod, all = all, imported = imported) + all || filter!(Base.Fix1(Base.isexported, mod), ssyms) filter!(ffunc, ssyms) macros = filter(x -> startswith(String(x), "@" * name), ssyms) syms = String[sprint((io,s)->Base.show_sym(io, s; allow_macroname=true), s) for s in ssyms if completes_global(String(s), name)] diff --git a/stdlib/REPL/test/replcompletions.jl b/stdlib/REPL/test/replcompletions.jl index ab44ba163058f..c62febe941619 100644 --- a/stdlib/REPL/test/replcompletions.jl +++ b/stdlib/REPL/test/replcompletions.jl @@ -1896,3 +1896,17 @@ let s = "Issue49892(fal" @test n in c end end + +@testset "public but non-exported symbols only complete qualified (#51331)" begin + c, r, res = test_complete("ispub") + @test res + @test "ispublic" ∉ c + + c, r, res = test_complete("Base.ispub") + @test res + @test "ispublic" ∈ c + + @test Base.ispublic(Base, :ispublic) + # If this last test starts failing, that's okay, just pick a new example symbol: + @test !Base.isexported(Base, :ispublic) +end