Skip to main content

W0061 - Invalid preprocessor condition

Error

-module(example).

-if(?UNDEFINED_MACRO).
%% ^^^^^^^^^^^^^^^^^^^ error: W0061: undefined macro 'UNDEFINED_MACRO' in condition
foo() -> ok.
-endif.

-if(unsupported_function()).
%% ^^^^^^^^^^^^^^^^^^^^^^^^ error: W0061: unsupported function call in condition
bar() -> ok.
-endif.

This diagnostic is triggered when a preprocessor condition (-if() or -elif()) contains an expression that cannot be evaluated. This includes references to undefined macros, unsupported function calls, or other expressions that cannot be statically resolved.

Common Causes

  1. Undefined macro: A macro referenced in the condition is not defined.
  2. Unsupported function call: The condition uses a function that ELP cannot evaluate at compile time (only a subset of functions is supported in -if() conditions).
  3. Unsupported expression: The condition contains an expression type that ELP cannot evaluate.

Impact

When ELP cannot evaluate a preprocessor condition, it treats the condition as "unknown". This means:

  • ELP cannot determine which branch of the conditional compilation is active
  • Diagnostics for code in both branches may be limited
  • Macro definitions within conditional blocks may not be properly tracked

Fix

Define the macro

If the condition references an undefined macro, define it:

-module(example).

-define(FEATURE_ENABLED, true).

-if(?FEATURE_ENABLED).
foo() -> ok.
-endif.

Use supported expressions

Simplify conditions to use only supported expression types:

-module(example).

% Supported: macro comparisons, boolean literals, basic arithmetic
-if(?OTP_RELEASE >= 25).
foo() -> ok.
-endif.

-if(true).
bar() -> ok.
-endif.

Relationship to W0062

If this diagnostic occurs in an included file (via -include() or -include_lib()), you will see W0062 instead, which reports the issue at the include directive location with a reference to the actual problem location.