W0039 - Macro Precedence Surprise
Warning
-module(main).
-define(MYOP(B,C), B + C).
foo(A,B,C) -> A * ?MYOP(B,C).
%% ^^^^^^^^^^ 💡 warning: The macro expansion can have unexpected precedence here
Explanation
At the surface level, when writing a macro call, it looks like a function call, and you have to look inside the macro to know what it expands to (or hover).
This can lead to surprises if the top level of the macro is a bare binary operation and it is used within another binary operation, as the precedence can then escape.
The example above will end up being parsed as (A * B) + C
, where at
first glance it might appear that it would be A * (B + C)
.
This diagnostic reports where this occurs, and offers to add parens at the macro call site, so leading to
foo(A,B,C) -> A * (?MYOP(B,C)).