Author yha
0 Stars
Updated Last
1 Year Ago
Started In
January 2021


Locate methods defined through macros

Methods defined through macros unhelpfully report their file and line numbers as those inside the macro definition. For example, this

# contents of foo.jl:
module Foo
  macro foo()
      :(bar() = x)  # line 3

  @foo() # line 6

# somewhere else:

gives an UndefVarError with the stack trace pointing to line 3, rather than 6.

This module provides functions finddef(method) and finddefs(f::Function) returning LineNumberNodes for the macro call sites:

julia> using FindDefinition

julia> finddef(first(methods(
:(#= [...]/foo.jl:6 =#)

julia> finddefs(
1-element Array{LineNumberNode,1}:
 :(#= [...]/foo.jl:6 =#)

Warning: The current implementation uses eval inside loaded modules to match method signatures. This is probably harmless, but does produce new gensymed symbols inside your loaded modules.

Required Packages

Used By Packages

No packages found.