From ad20f0a42372be7137e3777d24004a7067db3cbd Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Tue, 11 May 2021 14:21:05 +0200 Subject: [PATCH] REPL: Skip comments when assessing for missing packages, fixes #40776 (#40784) --- stdlib/REPL/src/REPL.jl | 1 + stdlib/REPL/test/repl.jl | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/stdlib/REPL/src/REPL.jl b/stdlib/REPL/src/REPL.jl index 0c5a6c6267cff..e777655806afa 100644 --- a/stdlib/REPL/src/REPL.jl +++ b/stdlib/REPL/src/REPL.jl @@ -191,6 +191,7 @@ function modules_to_be_loaded(ast, mods = Symbol[]) end return mods end +modules_to_be_loaded(::Nothing) = Symbol[] # comments are parsed as nothing """ start_repl_backend(repl_channel::Channel, response_channel::Channel) diff --git a/stdlib/REPL/test/repl.jl b/stdlib/REPL/test/repl.jl index 677d184f99eab..9b72b8db7b1c5 100644 --- a/stdlib/REPL/test/repl.jl +++ b/stdlib/REPL/test/repl.jl @@ -1298,27 +1298,32 @@ end @testset "Install missing packages via hooks" begin @testset "Parse AST for packages" begin - mods = REPL.modules_to_be_loaded(Meta.parse("using Foo")) + mods = REPL.modules_to_be_loaded(Base.parse_input_line("using Foo")) @test mods == [:Foo] - mods = REPL.modules_to_be_loaded(Meta.parse("import Foo")) + mods = REPL.modules_to_be_loaded(Base.parse_input_line("import Foo")) @test mods == [:Foo] - mods = REPL.modules_to_be_loaded(Meta.parse("using Foo, Bar")) + mods = REPL.modules_to_be_loaded(Base.parse_input_line("using Foo, Bar")) @test mods == [:Foo, :Bar] - mods = REPL.modules_to_be_loaded(Meta.parse("import Foo, Bar")) + mods = REPL.modules_to_be_loaded(Base.parse_input_line("import Foo, Bar")) @test mods == [:Foo, :Bar] - mods = REPL.modules_to_be_loaded(Meta.parse("if false using Foo end")) + mods = REPL.modules_to_be_loaded(Base.parse_input_line("if false using Foo end")) @test mods == [:Foo] - mods = REPL.modules_to_be_loaded(Meta.parse("if false if false using Foo end end")) + mods = REPL.modules_to_be_loaded(Base.parse_input_line("if false if false using Foo end end")) @test mods == [:Foo] - mods = REPL.modules_to_be_loaded(Meta.parse("if false using Foo, Bar end")) + mods = REPL.modules_to_be_loaded(Base.parse_input_line("if false using Foo, Bar end")) @test mods == [:Foo, :Bar] - mods = REPL.modules_to_be_loaded(Meta.parse("if false using Foo: bar end")) + mods = REPL.modules_to_be_loaded(Base.parse_input_line("if false using Foo: bar end")) @test mods == [:Foo] - mods = REPL.modules_to_be_loaded(Meta.parse("import Foo.bar as baz")) + mods = REPL.modules_to_be_loaded(Base.parse_input_line("import Foo.bar as baz")) @test mods == [:Foo] - mods = REPL.modules_to_be_loaded(Meta.parse("using .Foo")) - @test mods == [] + mods = REPL.modules_to_be_loaded(Base.parse_input_line("using .Foo")) + @test isempty(mods) + + mods = REPL.modules_to_be_loaded(Base.parse_input_line("# comment")) + @test isempty(mods) + mods = REPL.modules_to_be_loaded(Base.parse_input_line("Foo")) + @test isempty(mods) end end