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

isdef() seems to return true in any case #172

Closed
omlins opened this issue Dec 22, 2021 · 2 comments · Fixed by #199
Closed

isdef() seems to return true in any case #172

omlins opened this issue Dec 22, 2021 · 2 comments · Fixed by #199

Comments

@omlins
Copy link

omlins commented Dec 22, 2021

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
Copy link
Author

omlins commented Dec 22, 2021

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.

@fingolfin
Copy link
Contributor

Duplicate of issue #154 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants