Skip to content

Commit 8f192bd

Browse files
Missing package add prompt: Restrict which exprs to search in (#43457)
1 parent c04a3fd commit 8f192bd

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
@@ -194,7 +194,9 @@ function modules_to_be_loaded(ast::Expr, mods::Vector{Symbol} = Symbol[])
194194
end
195195
end
196196
for arg in ast.args
197-
arg isa Expr && modules_to_be_loaded(arg, mods)
197+
if arg isa Expr && arg.head in [:block, :if, :using, :import]
198+
modules_to_be_loaded(arg, mods)
199+
end
198200
end
199201
filter!(mod -> !in(String(mod), ["Base", "Main", "Core"]), mods) # Exclude special non-package modules
200202
return unique(mods)

stdlib/REPL/test/repl.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,15 @@ 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
13691378

0 commit comments

Comments
 (0)