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

Fix module_functions(m::Module) to skip names that aren't defined #5

Merged
merged 2 commits into from
Sep 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/LookingGlass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,15 @@ Return a list of the names of all functions defined in Module `m`.
module_functions_names(m::Module) =
[name
for name in names(m, all=true)
if Core.eval(m, name) isa Function && name ∉ (:include, :eval)]
if module_name_isfunction(m, name)]

function module_name_isfunction(m::Module, name::Symbol)
# TODO: Why is this isdefined() check needed? Why can `names(all=true)` return names
# that aren't defined?
return isdefined(m, name) &&
name ∉ (:include, :eval) && Core.eval(m, name) isa Function
end

"""
module_functions(m::Module) -> Dict{Symbol, Function}
Return a list of all the Function objects defined in Module `m`.
Expand Down Expand Up @@ -204,6 +212,7 @@ function _isconst_global(m::Module, s::Symbol)
b = _getbinding(m,s)
b != nothing && b.constp
end

#--- Compiler-Internal Julia Binding struct ------------------------------------------------
# Stores information about a variable binding, which we can interrogate for information
# such as whether a variable is a global `const`.
Expand Down Expand Up @@ -306,14 +315,14 @@ function supertypes(t::Type)
t0 = t
t1 = supertype(t)
result = Type[]
while t1 ≠ t0
while t1 ≠ t0
push!(result, t1)
t0, t1 = t1, supertype(t1)
end
return result
end

supertypes(x::T) where T = [T, supertypes(T)...]


end # module