Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing ?( in REPL help mode causes exception #52551

Closed
baggepinnen opened this issue Dec 15, 2023 · 5 comments · Fixed by #52555
Closed

Typing ?( in REPL help mode causes exception #52551

baggepinnen opened this issue Dec 15, 2023 · 5 comments · Fixed by #52555
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior REPL Julia's REPL (Read Eval Print Loop)

Comments

@baggepinnen
Copy link
Contributor

if I type ?( when in the REPL help mode (i.e., after an initial ?), I get the following error message

/tmp/julia-15244663a3/bin> ./julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.11.0-DEV.1089 (2023-12-13)
 _/ |\__'_|_|_|\__'_|  |  Commit 15244663a34 (2 days old master)
|__/                   |

help?> ?(┌ Error: Error in the keymap
│   exception = (UndefVarError(Symbol("@assume_effects"), Main), Union{Ptr{Nothing}, Base.InterpreterIP}[Ptr{Nothing} @0x00007f0753c39c6e, Ptr{Nothing} @0x00007f0753bd1c58, Ptr{Nothing} @0x00007f06884d87a0, Ptr{Nothing} @0x00007f0688730465, Ptr{Nothing} @0x00007f06884fd041, Ptr{Nothing} @0x00007f0688642463, Ptr{Nothing} @0x00007f0753bb102d, Ptr{Nothing} @0x00007f0688550c38, Ptr{Nothing} @0x00007f06885cc25e, Ptr{Nothing} @0x00007f0753bb102d, Ptr{Nothing} @0x00007f0753bc1b99, Ptr{Nothing} @0x00007f068860a31c, Ptr{Nothing} @0x00007f0688520f36, Ptr{Nothing} @0x00007f0753bb102d, Ptr{Nothing} @0x00007f06886b8ed5, Ptr{Nothing} @0x00007f068853029d, Ptr{Nothing} @0x00007f06885d3f3e, Ptr{Nothing} @0x00007f0753bb102d, Ptr{Nothing} @0x00007f06884fcb49, Ptr{Nothing} @0x00007f06885f6acd, Ptr{Nothing} @0x00007f06885d5c06, Ptr{Nothing} @0x00007f0753bb102d, Ptr{Nothing} @0x00007f0753bd63e1])
└ @ REPL.LineEdit /tmp/julia-15244663a3/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2821

@oscardssmith oscardssmith added bug Indicates an unexpected problem or unintended behavior REPL Julia's REPL (Read Eval Print Loop) labels Dec 15, 2023
@oscardssmith
Copy link
Member

I believe the problem is that the repl tab completion thinking it is defined in Base.

@Liozou
Copy link
Member

Liozou commented Dec 15, 2023

The explicit stacktrace is:

help?> ?(┌ Error: Error in the keymap
│   exception =
│    UndefVarError: `@assume_effects` not defined in `Main`
│    Suggestion: check for spelling errors or missing imports.
│    Hint: a global variable of this name also exists in Base.
│    Stacktrace:
│      [1] complete_any_methods(ex_org::Expr, callee_module::Module, context_module::Module, moreargs::Bool, shift::Bool)
│        @ REPL.REPLCompletions ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/REPLCompletions.jl:745
│      [2] completions(string::String, pos::Int64, context_module::Module, shift::Bool)
│        @ REPL.REPLCompletions ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/REPLCompletions.jl:1142
│      [3] complete_line(c::REPL.REPLCompletionProvider, s::REPL.LineEdit.PromptState, mod::Module)
│        @ REPL ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:560
│      [4] check_for_hint(s::REPL.LineEdit.MIState)
│        @ REPL.LineEdit ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:384
│      [5] (::REPL.LineEdit.var"#139#195")(s::REPL.LineEdit.MIState, data::Any, c::Union{Char, SubString{String}, String})
│        @ REPL.LineEdit ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2498
│      [6] #invokelatest#2
│        @ Base ./essentials.jl:955 [inlined]
│      [7] invokelatest
│        @ Base ./essentials.jl:952 [inlined]
│      [8] (::REPL.LineEdit.var"#27#28"{REPL.LineEdit.var"#139#195", String})(s::Any, p::Any)
│        @ REPL.LineEdit ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:1682
│      [9] prompt!(term::REPL.Terminals.TextTerminal, prompt::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
│        @ REPL.LineEdit ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2819
│     [10] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
│        @ REPL.LineEdit ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2721
│     [11] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
│        @ REPL ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:1352
│     [12] (::REPL.var"#64#70"{REPL.LineEditREPL, REPL.REPLBackendRef})()
│        @ REPL ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:401
└ @ REPL.LineEdit ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2821

@aviatesk
Copy link
Member

I don‘t think this is rooted from the inference engine for REPL completion.

@oscardssmith
Copy link
Member

The reason I thought it was is because the stack trace suggests

│        @ REPL.REPLCompletions ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/REPLCompletions.jl:745```

@Liozou
Copy link
Member

Liozou commented Dec 15, 2023

This is indeed independent from the inference engine. Actually it's an issue that dates back to #38791, and it only surfaces now because of #51345.

To make it visible on previous versions of julia, execute:

julia> module Foo
           export bar
           bar(x) = nothing
       end;

julia> import .Foo

julia>  ?(┌ Error: Error in the keymap
│   exception =
│    UndefVarError: bar not defined
│    Stacktrace:
│      [1] complete_any_methods(ex_org::Expr, callee_module::Module, context_module::Module, moreargs::Bool, shift::Bool)
│        @ REPL.REPLCompletions /LionelSSDext4/liozou/julia-1.8.5/share/julia/stdlib/v1.8/REPL/src/REPLCompletions.jl:564
│      [2] completions(string::String, pos::Int64, context_module::Module, shift::Bool)
│        @ REPL.REPLCompletions /LionelSSDext4/liozou/julia-1.8.5/share/julia/stdlib/v1.8/REPL/src/REPLCompletions.jl:787
│      [3] complete_line(c::REPL.REPLCompletionProvider, s::REPL.LineEdit.PromptState)
│        @ REPL /LionelSSDext4/liozou/julia-1.8.5/share/julia/stdlib/v1.8/REPL/src/REPL.jl:497
│      [4] complete_line(s::REPL.LineEdit.PromptState, repeats::Int64)
│        @ REPL.LineEdit /LionelSSDext4/liozou/julia-1.8.5/share/julia/stdlib/v1.8/REPL/src/LineEdit.jl:353
│      [5] complete_line(s::REPL.LineEdit.MIState)
│        @ REPL.LineEdit /LionelSSDext4/liozou/julia-1.8.5/share/julia/stdlib/v1.8/REPL/src/LineEdit.jl:344
│      [6] edit_tab(s::REPL.LineEdit.MIState, jump_spaces::Bool, delete_trailing::Bool) (repeats 2 times)
│        @ REPL.LineEdit /LionelSSDext4/liozou/julia-1.8.5/share/julia/stdlib/v1.8/REPL/src/LineEdit.jl:2180
│      [7] (::REPL.LineEdit.var"#112#166")(::REPL.LineEdit.MIState, ::Any, ::Vararg{Any})
│        @ REPL.LineEdit /LionelSSDext4/liozou/julia-1.8.5/share/julia/stdlib/v1.8/REPL/src/LineEdit.jl:2226
│      [8] #invokelatest#2
│        @ ./essentials.jl:729 [inlined]
│      [9] invokelatest
│        @ ./essentials.jl:726 [inlined]
│     [10] (::REPL.LineEdit.var"#25#26"{REPL.LineEdit.var"#112#166", String})(s::Any, p::Any)
│        @ REPL.LineEdit /LionelSSDext4/liozou/julia-1.8.5/share/julia/stdlib/v1.8/REPL/src/LineEdit.jl:1472
│     [11] prompt!(term::REPL.Terminals.TextTerminal, prompt::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
│        @ REPL.LineEdit /LionelSSDext4/liozou/julia-1.8.5/share/julia/stdlib/v1.8/REPL/src/LineEdit.jl:2603
│     [12] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
│        @ REPL.LineEdit /LionelSSDext4/liozou/julia-1.8.5/share/julia/stdlib/v1.8/REPL/src/LineEdit.jl:2505
│     [13] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
│        @ REPL /LionelSSDext4/liozou/julia-1.8.5/share/julia/stdlib/v1.8/REPL/src/REPL.jl:1248
│     [14] (::REPL.var"#49#54"{REPL.LineEditREPL, REPL.REPLBackendRef})()
│        @ REPL ./task.jl:484
└ @ REPL.LineEdit /cache/build/default-amdci4-2/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/LineEdit.jl:2605

@Liozou Liozou assigned Liozou and unassigned aviatesk Dec 15, 2023
aviatesk added a commit that referenced this issue Dec 20, 2023
Fix #52551.

This PR ensures that a `SomeModule.?(...#TAB` completion can only
suggests method `foo` such that `SomeModule.foo` exists (by checking
`isdefined(SomeModule, :foo)`). This is equivalent, I believe, to the
initial implementation of #38791,
less the bug.

Now that we have #51345, we may want to relax the above condition
somewhat to include public names present in modules loaded into
`SomeModule`, so that, for instance, a direct completion of `?(` would
include `@assume_effects`. This could be good for method exploration
because even though typing `@assume_effects` with no qualification in
`Main` will error, the error now includes the helpful message
```
Hint: a global variable of this name also exists in Base.
```
But that can wait for a later PR anyway, this one is just the bugfix.

The bug mentioned at
#52551 (comment)
dates from the initial #38791 so this could be backported as far back as
v1.8.

---------

Co-authored-by: Shuhei Kadowaki <[email protected]>
KristofferC pushed a commit that referenced this issue Dec 23, 2023
Fix #52551.

This PR ensures that a `SomeModule.?(...#TAB` completion can only
suggests method `foo` such that `SomeModule.foo` exists (by checking
`isdefined(SomeModule, :foo)`). This is equivalent, I believe, to the
initial implementation of #38791,
less the bug.

Now that we have #51345, we may want to relax the above condition
somewhat to include public names present in modules loaded into
`SomeModule`, so that, for instance, a direct completion of `?(` would
include `@assume_effects`. This could be good for method exploration
because even though typing `@assume_effects` with no qualification in
`Main` will error, the error now includes the helpful message
```
Hint: a global variable of this name also exists in Base.
```
But that can wait for a later PR anyway, this one is just the bugfix.

The bug mentioned at
#52551 (comment)
dates from the initial #38791 so this could be backported as far back as
v1.8.

---------

Co-authored-by: Shuhei Kadowaki <[email protected]>
(cherry picked from commit a987f56)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants