Skip to content

Commit

Permalink
Missing package add prompt: Restrict which exprs to search in (JuliaL…
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth authored and LilithHafner committed Mar 8, 2022
1 parent b51886e commit 7f4be67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ function modules_to_be_loaded(ast::Expr, mods::Vector{Symbol} = Symbol[])
end
end
for arg in ast.args
arg isa Expr && modules_to_be_loaded(arg, mods)
if arg isa Expr && arg.head in [:block, :if, :using, :import]
modules_to_be_loaded(arg, mods)
end
end
filter!(mod -> !in(String(mod), ["Base", "Main", "Core"]), mods) # Exclude special non-package modules
return unique(mods)
Expand Down
9 changes: 9 additions & 0 deletions stdlib/REPL/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,15 @@ end

mods = REPL.modules_to_be_loaded(Base.parse_input_line("Foo"))
@test isempty(mods)

mods = REPL.modules_to_be_loaded(Base.parse_input_line("@eval using Foo"))
@test isempty(mods)
mods = REPL.modules_to_be_loaded(Base.parse_input_line("begin using Foo; @eval using Bar end"))
@test mods == [:Foo]
mods = REPL.modules_to_be_loaded(Base.parse_input_line("Core.eval(Main,\"using Foo\")"))
@test isempty(mods)
mods = REPL.modules_to_be_loaded(Base.parse_input_line("begin using Foo; Core.eval(Main,\"using Foo\") end"))
@test mods == [:Foo]
end
end

Expand Down

0 comments on commit 7f4be67

Please sign in to comment.