MacroTools.jl icon indicating copy to clipboard operation
MacroTools.jl copied to clipboard

`isdef()` seems to return true in any case

Open omlins opened this issue 3 years ago • 2 comments

help?> MacroTools.isdef
  Test for function definition expressions.

julia> MacroTools.isdef(:(f() = 3))
true

julia> MacroTools.isdef(:(f()))
true

julia> MacroTools.isdef(:ix)
true

omlins avatar Dec 22 '21 12:12 omlins

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.

omlins avatar Dec 22 '21 15:12 omlins

Duplicate of issue #154 ?

fingolfin avatar Dec 27 '21 22:12 fingolfin