Skip to content

MethodError when using function defined via macro #93

@cjwyett

Description

@cjwyett

Hi

Reproducible example:

macro makefn(name)
    name = Symbol(name)
    quote
        $(esc(name))() = print("hello")
    end
end

julia> @makefn f
f (generic function with 1 method)

julia> f()
hello

julia> @code_string f()
ERROR: MethodError: no method matching +(::Nothing, ::Int64)
Closest candidates are:
  +(::Any, ::Any, ::Any, ::Any...) at /usr/share/julia/base/operators.jl:655
  +(::T, ::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} at /usr/share/julia/base/int.jl:87
  +(::Base.TwicePrecision, ::Number) at /usr/share/julia/base/twiceprecision.jl:279
  ...
Stacktrace:
 [1] definition(#unused#::Type{String}, method::Method)
   @ CodeTracking ~/.julia/packages/CodeTracking/zfc7r/src/CodeTracking.jl:230
 [2] code_string(f::Function, t::Type)
   @ CodeTracking ~/.julia/packages/CodeTracking/zfc7r/src/CodeTracking.jl:299
 [3] top-level scope
   @ REPL[5]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions