@@ -33,35 +33,19 @@ function UndefVarError_hint(io::IO, ex::UndefVarError)
3333    if  isdefined (ex, :scope )
3434        scope =  ex. scope
3535        if  scope isa  Module
36-             bnd =  ccall (:jl_get_module_binding , Any, (Any, Any, Cint), scope, var, true ):: Core.Binding 
37-             if  isdefined (bnd, :owner )
38-                 owner =  bnd. owner
39-                 if  owner ===  bnd
40-                     print (io, " \n Suggestion: add an appropriate import or assignment. This global was declared but not assigned."  )
41-                 end 
36+             bpart =  Base. lookup_binding_partition (Base. get_world_counter (), GlobalRef (scope, var))
37+             kind =  Base. binding_kind (bpart)
38+             if  kind ===  Base. BINDING_KIND_GLOBAL ||  kind ===  Base. BINDING_KIND_CONST ||  kind ==  Base. BINDING_KIND_DECLARED
39+                 print (io, " \n Suggestion: add an appropriate import or assignment. This global was declared but not assigned."  )
40+             elseif  kind ===  Base. BINDING_KIND_FAILED
41+                 print (io, " \n Hint: It looks like two or more modules export different "  ,
42+                 " bindings with this name, resulting in ambiguity. Try explicitly "  ,
43+                 " importing it from a particular module, or qualifying the name "  ,
44+                 " with the module it should come from."  )
45+             elseif  kind ===  Base. BINDING_KIND_GUARD
46+                 print (io, " \n Suggestion: check for spelling errors or missing imports."  )
4247            else 
43-                 owner =  ccall (:jl_binding_owner , Ptr{Cvoid}, (Any, Any), scope, var)
44-                 if  C_NULL  ==  owner
45-                     #  No global of this name exists in this module.
46-                     #  This is the common case, so do not print that information.
47-                     #  It could be the binding was exported by two modules, which we can detect
48-                     #  by the `usingfailed` flag in the binding:
49-                     if  false  #  TODO : #isdefined(bnd, :flags) && Bool(bnd.flags >> 4 & 1) # magic location of the `usingfailed` flag
50-                         print (io, " \n Hint: It looks like two or more modules export different "  ,
51-                               " bindings with this name, resulting in ambiguity. Try explicitly "  ,
52-                               " importing it from a particular module, or qualifying the name "  ,
53-                               " with the module it should come from."  )
54-                     else 
55-                         print (io, " \n Suggestion: check for spelling errors or missing imports."  )
56-                     end 
57-                     owner =  bnd
58-                 else 
59-                     owner =  unsafe_pointer_to_objref (owner):: Core.Binding 
60-                 end 
61-             end 
62-             if  owner != =  bnd
63-                 #  this could use jl_binding_dbgmodule for the exported location in the message too
64-                 print (io, " \n Suggestion: this global was defined as `$(owner. globalref) ` but not assigned a value."  )
48+                 print (io, " \n Suggestion: this global was defined as `$(bpart. restriction. globalref) ` but not assigned a value."  )
6549            end 
6650        elseif  scope ===  :static_parameter 
6751            print (io, " \n Suggestion: run Test.detect_unbound_args to detect method arguments that do not fully constrain a type parameter."  )
0 commit comments