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

Group import hints #56753

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

ajwheeler
Copy link

This is my attempt to resolve #53000.

julia> solve
ERROR: UndefVarError: `solve` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Hint: a global variable of this name also exists in CommonSolve.
    - Also exported by SciMLBase.
    - Also exported by DiffEqBase.
    - Also exported by JumpProcesses.
    - Also exported by LinearSolve.
    - Also exported by BracketingNonlinearSolve (loaded but not imported in Main).
    - Also exported by SimpleNonlinearSolve.
    - Also exported by NonlinearSolve.
    - Also exported by OrdinaryDiffEqLowStorageRK (loaded but not imported in Main).
    - Also exported by OrdinaryDiffEqSSPRK (loaded but not imported in Main).
    - Also exported by OrdinaryDiffEqVerner (loaded but not imported in Main).
    - Also exported by OrdinaryDiffEqBDF (loaded but not imported in Main).
    - Also exported by OrdinaryDiffEqTsit5 (loaded but not imported in Main).
    - Also exported by OrdinaryDiffEqRosenbrock (loaded but not imported in Main).
    - Also exported by OrdinaryDiffEqDefault (loaded but not imported in Main).
    - Also exported by Sundials.

I would have beefed up the test case, but can't follow how it works.

stdlib/REPL/src/REPL.jl Outdated Show resolved Hide resolved
@Keno
Copy link
Member

Keno commented Dec 4, 2024

Seems sensible overall, modulo comment.

@Keno
Copy link
Member

Keno commented Dec 4, 2024

Does need a test though.

@LilithHafner LilithHafner added the error messages Better, more actionable error messages label Dec 4, 2024
@LilithHafner
Copy link
Member

There's also some trailing whitespace that needs to be removed. You can see where on the "files changd" tab of this PR. (Some editors have an option to strip trailing whitespace automatically)

@LilithHafner LilithHafner added the needs tests Unit tests are required for this change label Dec 4, 2024
@ajwheeler
Copy link
Author

In thinking about how to test this, I've come across what may be a problem. If I do

module A
export f
f() = 0.0
end

module B
import ..A: f
export f
end

module C
import ..B: f
public f
end

module D
public f
f() = 1.0
end

append!(Base.loaded_modules_order, [A, B, C, D]) # is there a less gross way?
import .B

Then the hints for julia> f look like this

ERROR: UndefVarError: `f` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Hint: a global variable of this name also exists in Main.A.
    - Also exported by Main.B (loaded but not imported in Main).
    - Also made available as public by Main.C (loaded but not imported in Main).
Hint: a global variable of this name also exists in Main.D.

The problem here is that (unlike C), B is imported.

The same thing happens with 1.11.

hints on 1.11
julia> f
ERROR: UndefVarError: `f` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Hint: a global variable of this name may be made accessible by importing Main.A in the current active module Main
Hint: a global variable of this name may be made accessible by importing Main.B in the current active module Main
Hint: a global variable of this name may be made accessible by importing Main.C in the current active module Main
Hint: a global variable of this name may be made accessible by importing Main.D in the current active module Main

I think the problem arises from calling Symbol(m), where m is a Module, but I might be confused.

I would welcome input here about whether or not this is out of scope for this PR, and whether there is a better way to test this.

@ararslan
Copy link
Member

I think the problem arises from calling Symbol(m), where m is a Module, but I might be confused.

I haven't looked closely enough to determine whether Symbol(m) is the problem but if you suspect it is then you could try nameof(m) instead. (However, note that nameof here isn't fully equivalent; consider e.g. Symbol(Base.Broadcast) vs. nameof(Base.Broadcast). To get the same behavior, you'd need Symbol(join(fullname(m), '.')).)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error messages Better, more actionable error messages needs tests Unit tests are required for this change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Group import hint by bindings
4 participants