Skip to content

Commit 3b7e9f0

Browse files
IanButterworthKristofferC
authored andcommitted
Missing package add prompt: Restrict which exprs to search in (#43457)
(cherry picked from commit 8f192bd)
1 parent f4a0c7c commit 3b7e9f0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

stdlib/REPL/src/REPL.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ function modules_to_be_loaded(ast::Expr, mods::Vector{Symbol} = Symbol[])
193193
end
194194
end
195195
for arg in ast.args
196-
arg isa Expr && modules_to_be_loaded(arg, mods)
196+
if arg isa Expr && arg.head in [:block, :if, :using, :import]
197+
modules_to_be_loaded(arg, mods)
198+
end
197199
end
198200
filter!(mod -> !in(String(mod), ["Base", "Main", "Core"]), mods) # Exclude special non-package modules
199201
return unique(mods)

stdlib/REPL/test/repl.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,5 +1364,14 @@ end
13641364

13651365
mods = REPL.modules_to_be_loaded(Base.parse_input_line("Foo"))
13661366
@test isempty(mods)
1367+
1368+
mods = REPL.modules_to_be_loaded(Base.parse_input_line("@eval using Foo"))
1369+
@test isempty(mods)
1370+
mods = REPL.modules_to_be_loaded(Base.parse_input_line("begin using Foo; @eval using Bar end"))
1371+
@test mods == [:Foo]
1372+
mods = REPL.modules_to_be_loaded(Base.parse_input_line("Core.eval(Main,\"using Foo\")"))
1373+
@test isempty(mods)
1374+
mods = REPL.modules_to_be_loaded(Base.parse_input_line("begin using Foo; Core.eval(Main,\"using Foo\") end"))
1375+
@test mods == [:Foo]
13671376
end
13681377
end

0 commit comments

Comments
 (0)