Skip to content

Commit 8334eb9

Browse files
IanButterworthAmit Shirodkar
authored and
Amit Shirodkar
committed
REPL: Skip comments when assessing for missing packages, fixes JuliaLang#40776 (JuliaLang#40784)
1 parent be8fd2c commit 8334eb9

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

stdlib/REPL/src/REPL.jl

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ function modules_to_be_loaded(ast, mods = Symbol[])
191191
end
192192
return mods
193193
end
194+
modules_to_be_loaded(::Nothing) = Symbol[] # comments are parsed as nothing
194195

195196
"""
196197
start_repl_backend(repl_channel::Channel, response_channel::Channel)

stdlib/REPL/test/repl.jl

+16-11
Original file line numberDiff line numberDiff line change
@@ -1298,27 +1298,32 @@ end
12981298

12991299
@testset "Install missing packages via hooks" begin
13001300
@testset "Parse AST for packages" begin
1301-
mods = REPL.modules_to_be_loaded(Meta.parse("using Foo"))
1301+
mods = REPL.modules_to_be_loaded(Base.parse_input_line("using Foo"))
13021302
@test mods == [:Foo]
1303-
mods = REPL.modules_to_be_loaded(Meta.parse("import Foo"))
1303+
mods = REPL.modules_to_be_loaded(Base.parse_input_line("import Foo"))
13041304
@test mods == [:Foo]
1305-
mods = REPL.modules_to_be_loaded(Meta.parse("using Foo, Bar"))
1305+
mods = REPL.modules_to_be_loaded(Base.parse_input_line("using Foo, Bar"))
13061306
@test mods == [:Foo, :Bar]
1307-
mods = REPL.modules_to_be_loaded(Meta.parse("import Foo, Bar"))
1307+
mods = REPL.modules_to_be_loaded(Base.parse_input_line("import Foo, Bar"))
13081308
@test mods == [:Foo, :Bar]
13091309

1310-
mods = REPL.modules_to_be_loaded(Meta.parse("if false using Foo end"))
1310+
mods = REPL.modules_to_be_loaded(Base.parse_input_line("if false using Foo end"))
13111311
@test mods == [:Foo]
1312-
mods = REPL.modules_to_be_loaded(Meta.parse("if false if false using Foo end end"))
1312+
mods = REPL.modules_to_be_loaded(Base.parse_input_line("if false if false using Foo end end"))
13131313
@test mods == [:Foo]
1314-
mods = REPL.modules_to_be_loaded(Meta.parse("if false using Foo, Bar end"))
1314+
mods = REPL.modules_to_be_loaded(Base.parse_input_line("if false using Foo, Bar end"))
13151315
@test mods == [:Foo, :Bar]
1316-
mods = REPL.modules_to_be_loaded(Meta.parse("if false using Foo: bar end"))
1316+
mods = REPL.modules_to_be_loaded(Base.parse_input_line("if false using Foo: bar end"))
13171317
@test mods == [:Foo]
13181318

1319-
mods = REPL.modules_to_be_loaded(Meta.parse("import Foo.bar as baz"))
1319+
mods = REPL.modules_to_be_loaded(Base.parse_input_line("import Foo.bar as baz"))
13201320
@test mods == [:Foo]
1321-
mods = REPL.modules_to_be_loaded(Meta.parse("using .Foo"))
1322-
@test mods == []
1321+
mods = REPL.modules_to_be_loaded(Base.parse_input_line("using .Foo"))
1322+
@test isempty(mods)
1323+
1324+
mods = REPL.modules_to_be_loaded(Base.parse_input_line("# comment"))
1325+
@test isempty(mods)
1326+
mods = REPL.modules_to_be_loaded(Base.parse_input_line("Foo"))
1327+
@test isempty(mods)
13231328
end
13241329
end

0 commit comments

Comments
 (0)