Skip to content

Commit

Permalink
fix overlapping definitions of Base.active_module and `REPL.active_…
Browse files Browse the repository at this point in the history
…module`
  • Loading branch information
JeffBezanson committed Jul 30, 2024
1 parent 686804d commit a1c40de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
7 changes: 4 additions & 3 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a1c40de

Please sign in to comment.