[erlang-bugs] Macro expansion is confused by anonymous functions

Hans Bolinder hans.bolinder@REDACTED
Thu Jun 25 08:35:29 CEST 2009


[John Hughes:]
> The following module is wrongly rejected by the macro processor:
> 
> -module(bug).
> 
> -define(ID(X),X).
> 
> f() ->
>     ?ID(begin fun() -> ok end, ok end).
> 
> The error message is "argument mismatch for macro ''ID''". It looks
> as though the end that terminates the fun is matched against the
> begin at the start of the macro argument. Enclosing the fun in
> brackets makes the macro processor accept it. Omitting the ", ok"
> also makes the macro processor accept it, somewhat to my surprise!

What a coincidence. I found the very same bug yesterday. :)

Adding this clause seems to fix the problem.

macro_arg([{'fun',Lc}|[{'(',_}|_]=Toks], E, Arg) ->
    macro_arg(Toks, ['end'|E], [{'fun',Lc}|Arg]);

There is a similar bug for 'query'/'end'. (Mnemosyne is deprecated.)

BTW, I've found another bug in epp, and I'm looking for more.

Thanks.

Best regards,

Hans Bolinder, Erlang/OTP team, Ericsson


More information about the erlang-bugs mailing list