Skip to main content

L1325 - Obsolete Boolean Operator

Warning

foo(X) -> X > 3 or is_tuple(X).
%% ^^ warning: use the short circuiting 'orelse' instead

Explanation

The and and or operators always evaluate both sides, unlike andalso and orelse which short-circuit. They also have unexpected precedence — for example, X > 3 or is_tuple(X) parses as X > (3 or is_tuple(X)).

Use andalso and orelse instead:

%% Instead of:
foo(X) -> X > 3 or is_tuple(X).

%% Write:
foo(X) -> X > 3 orelse is_tuple(X).

This warning can be suppressed with -compile(nowarn_obsolete_bool_op).