MacroTools.jl
MacroTools.jl copied to clipboard
`isdef()` seems to return true in any case
help?> MacroTools.isdef
Test for function definition expressions.
julia> MacroTools.isdef(:(f() = 3))
true
julia> MacroTools.isdef(:(f()))
true
julia> MacroTools.isdef(:ix)
true
The function isdef is defined as follows (copied from here):
isdef(ex) = isshortdef(ex) || longdef1(ex) !== nothing
The problem is that longdef1(ex) !== nothing does not at all check if ex is a function: if ex is not matched as short function definitions within longdef1, it is returned unchanged (see here). As result, isdef(ex) only returns false in one single case: when ex is nothing.
In MacroTools.splitdef, the check if an expression is a function is done differently - and hopefully correctly - using longdef1 (copied from here):
@capture(longdef1(fdef), function (fcall_ | fcall_) body_ end)
I do not quite follow what the or-statement here ((fcall_ | fcall_)) is supposed to do though.
Duplicate of issue #154 ?