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

Don't print "No global of this name exists in this module." on UndefValError #52280

Merged
merged 1 commit into from
Nov 23, 2023

Conversation

LilithHafner
Copy link
Member

When we get an UndefValError, we know !isdefined(Main, :a). This is highly correlated with "No global of this name exists in this module." Consequently, the second sentence in the suggestion

julia> a
ERROR: UndefVarError: `a` not defined in `Main`
Suggestion: check for spelling errors or missing imports. No global of this name exists in this module.

Carries less than one bit of information. I don't like showing users hints that carry less than one bit per sentence. In the cases where a global does exist, that sentence carries much more information and is worth keeping. In any event, a super power user can infer from the lack of that sentence that no global exists.

Master

julia> function f()
           global a = 2
       end
f (generic function with 1 method)

julia> a
ERROR: UndefVarError: `a` not defined in `Main`
Suggestion: add an appropriate import or assignment. This global was declared but not assigned.

julia> b
ERROR: UndefVarError: `b` not defined in `Main`
Suggestion: check for spelling errors or missing imports. No global of this name exists in this module.

PR

julia> function f()
           global a = 2
       end
f (generic function with 1 method)

julia> a
ERROR: UndefVarError: `a` not defined in `Main`
Suggestion: add an appropriate import or assignment. This global was declared but not assigned.

julia> b
ERROR: UndefVarError: `b` not defined in `Main`
Suggestion: check for spelling errors or missing imports.

Fixes #52273 (cc @vtjnash @jishnub)

@LilithHafner LilithHafner merged commit 9884e44 into master Nov 23, 2023
5 of 7 checks passed
@LilithHafner LilithHafner deleted the lh/global-hint-fixup branch November 23, 2023 16:16
mkitti pushed a commit to mkitti/julia that referenced this pull request Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redundant suggestion printed on an UndefVarError on nightly
2 participants