W0019 - Expression can be simplified
Warning
-module(main).
foo(X) ->
bar([] ++ [1]).
%% ^^^^^^^^^ 💡 warning: Can be simplified to `[1]`.
Explanation
The warning indicates that an expression can be trivially simplified to a more concise form without changing its behavior. This diagnostic helps improve code readability and can be especially useful during code refactoring and optimization.
Supported Simplifications
List Operations
- Append with empty list:
[] ++ X
→X
andX ++ []
→X
- Subtract with empty list:
[] -- X
→[]
andX -- []
→X
Arithmetic Operations
- Addition with zero:
0 + X
→X
andX + 0
→X
- Subtraction with zero:
0 - X
→-X
andX - 0
→X
- Multiplication by one:
1 * X
→X
andX * 1
→X
- Division by one:
X div 1
→X
- Remainder by one:
X rem 1
→0
Boolean Operations
- Short-circuit evaluation:
true andalso X
→X
andfalse orelse X
→X
- Negation of literals:
not true
→false
andnot false
→true
Note on Macros
This diagnostic does not apply to expressions that involve macro expansions, as simplifying them might change the intended behavior or readability of the code.