diff --git a/stdlib/InteractiveUtils/src/macros.jl b/stdlib/InteractiveUtils/src/macros.jl index 290f05eb86730..9d6a34ead21da 100644 --- a/stdlib/InteractiveUtils/src/macros.jl +++ b/stdlib/InteractiveUtils/src/macros.jl @@ -830,5 +830,7 @@ macro activate(what) options = map(options) do opt Expr(:kw, opt, true) end - return :(Base.require($__module__, $(QuoteNode(Component))).activate!(; $(options...))) + return :(let M = Base.require($__module__, $(QuoteNode(Component))) + @invokelatest M.activate!(; $(options...)) + end) end diff --git a/stdlib/InteractiveUtils/test/runtests.jl b/stdlib/InteractiveUtils/test/runtests.jl index 825dc579d514a..48c89ba746d9d 100644 --- a/stdlib/InteractiveUtils/test/runtests.jl +++ b/stdlib/InteractiveUtils/test/runtests.jl @@ -1054,3 +1054,17 @@ end # module using .OuterModule @test_nowarn subtypes(Integer); end + +let code = """ + using InteractiveUtils + @activate Compiler[:codegen, :reflection] + println("done compiling") + """ + orig_compiler = realpath(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "Compiler")) + mktempdir() do dir + new_compiler = joinpath(dir, "Compiler") + cp(orig_compiler, new_compiler) + output = read(`$(Base.julia_cmd()) -g0 -O0 --startup-file=no --project=$(new_compiler) -e $code`, String) + @test occursin("done compiling", output) + end +end