From a1c40de24785a90333fd45327c822670ee917cf2 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Tue, 30 Jul 2024 16:02:10 -0400 Subject: [PATCH] fix overlapping definitions of `Base.active_module` and `REPL.active_module` --- base/show.jl | 7 ++++--- stdlib/REPL/src/REPL.jl | 9 +++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/base/show.jl b/base/show.jl index c1ad45af5cc83..95962aa581fb6 100644 --- a/base/show.jl +++ b/base/show.jl @@ -514,9 +514,10 @@ function _show_default(io::IO, @nospecialize(x)) end function active_module() - REPL = REPL_MODULE_REF[] - REPL === Base && return Main - return invokelatest(REPL.active_module)::Module + if !@isdefined(active_repl) + return Main + end + return invokelatest(active_module, active_repl)::Module end # Check if a particular symbol is exported from a standard library module diff --git a/stdlib/REPL/src/REPL.jl b/stdlib/REPL/src/REPL.jl index 558f6ed9cab6f..ac35e6bcd6f24 100644 --- a/stdlib/REPL/src/REPL.jl +++ b/stdlib/REPL/src/REPL.jl @@ -17,6 +17,8 @@ module REPL Base.Experimental.@optlevel 1 Base.Experimental.@max_methods 1 +import Base: active_module + function UndefVarError_hint(io::IO, ex::UndefVarError) var = ex.var if var === :or @@ -327,7 +329,7 @@ function warn_on_non_owning_accesses(current_mod, ast) end return ast end -warn_on_non_owning_accesses(ast) = warn_on_non_owning_accesses(REPL.active_module(), ast) +warn_on_non_owning_accesses(ast) = warn_on_non_owning_accesses(active_module(), ast) const repl_ast_transforms = Any[softscope, warn_on_non_owning_accesses] # defaults for new REPL backends @@ -758,11 +760,6 @@ REPLCompletionProvider() = REPLCompletionProvider(LineEdit.Modifiers()) mutable struct ShellCompletionProvider <: CompletionProvider end struct LatexCompletions <: CompletionProvider end -function active_module() # this method is also called from Base - isdefined(Base, :active_repl) || return Main - Base.active_repl === nothing && return Main - return active_module(Base.active_repl::AbstractREPL) -end active_module((; mistate)::LineEditREPL) = mistate === nothing ? Main : mistate.active_module active_module(::AbstractREPL) = Main active_module(d::REPLDisplay) = active_module(d.repl)