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: correctly follow find definitions for macros #374

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/linting/checks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ function sig_match_any(func::EXPR, x, call_counts, tls::Scope, env::ExternalEnv)
end

function get_method(name::EXPR)
f = maybe_get_parent_fexpr(name, x -> CSTParser.defines_function(x) || CSTParser.defines_struct(x))
f = maybe_get_parent_fexpr(name, x -> CSTParser.defines_function(x) || CSTParser.defines_struct(x) || CSTParser.defines_macro(x))
if f !== nothing && CSTParser.get_name(f) == name
return f
end
Expand Down
23 changes: 23 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2005,3 +2005,26 @@ end
""")
@test isempty(StaticLint.collect_hints(cst, server))
end

@testset "macro definition" begin
cst = parse_and_pass("""
module JumpToMacroDoesNotWork
export @mymacro

macro mymacro()
end
end

JumpToMacroDoesNotWork.@mymacro(1+1)
""")
m = cst.args[end].args[1].args[2].args[1]
methods = Set()
for r in m.meta.ref.refs
m = StaticLint.get_method(r)
if m !== nothing
push!(methods, m)
end
end

@test !isempty(methods)
end