diff --git a/src/StaticLint.jl b/src/StaticLint.jl index c13028e1..00a53327 100644 --- a/src/StaticLint.jl +++ b/src/StaticLint.jl @@ -83,7 +83,7 @@ function (state::Toplevel)(x::EXPR) if state.modified_exprs !== nothing && x in state.modified_exprs state.in_modified_expr = true end - if CSTParser.defines_function(x) || CSTParser.defines_macro(x) || headof(x) === :export + if CSTParser.defines_function(x) || CSTParser.defines_macro(x) || headof(x) === :export || headof(x) === :public if state.in_modified_expr push!(state.delayed, x) else @@ -115,6 +115,7 @@ function (state::Delayed)(x::EXPR) mark_globals(x, state) handle_macro(x, state) s0 = scopes(x, state) + resolve_ref(x, state) old = flag!(state, x) diff --git a/src/bindings.jl b/src/bindings.jl index 8efa53a2..3e862976 100644 --- a/src/bindings.jl +++ b/src/bindings.jl @@ -11,16 +11,18 @@ mutable struct Binding val::Union{Binding,EXPR,SymbolServer.SymStore,Nothing} type::Union{Binding,SymbolServer.SymStore,Nothing} refs::Vector{Any} + is_public::Bool end -Binding(x::EXPR) = Binding(CSTParser.get_name(x), x, nothing, []) +Binding(x::EXPR) = Binding(CSTParser.get_name(x), x, nothing, [], false) +Binding(name, val, type, refs) = Binding(name, val, type, refs, false) function Base.show(io::IO, b::Binding) printstyled(io, " Binding(", to_codeobject(b.name), - b.type === nothing ? "" : ":: ", - b.refs isa Vector ? "($(length(b.refs)) refs))" : ")", color=:blue) + b.is_public ? "ᵖ" : "", + b.type === nothing ? "" : "::($(b.type))", + b.refs isa Vector ? " ($(length(b.refs)) refs))" : ")", color=:blue) end - hasbinding(x::EXPR) = hasmeta(x) && hasbinding(x.meta) bindingof(x) = nothing bindingof(x::EXPR) = bindingof(x.meta) diff --git a/src/references.jl b/src/references.jl index 582242be..7fc68b5c 100644 --- a/src/references.jl +++ b/src/references.jl @@ -69,6 +69,9 @@ function resolve_ref(x::EXPR, scope::Scope, state::State)::Bool mn === nothing && return true if scopehasbinding(scope, mn) + if x.parent.head === :public + scope.names[mn].is_public = true + end setref!(x, scope.names[mn]) resolved = true elseif scope.modules isa Dict && length(scope.modules) > 0