W0018 - Unexpected semicolon or dot
Warning
-module(main).
foo(1)->2;
foo(2)->3.
%% ^ warning: Unexpected '.'
foo(3)->4.
-module(main).
foo(1)->2;
foo(2)->3;
%% ^ warning: Unexpected ';'
Explanation
The warning message indicates that there is an unexpected separator in a function clause sequence. This diagnostic is generated when:
- Unexpected dot (
.
) - A dot appears where a semicolon is expected between function clauses - Unexpected semicolon (
;
) - A semicolon appears where a dot is expected at the end of a function definition
In Erlang, function clauses within the same function must be separated by
semicolons (;
), and the final clause of a function must end with a dot (.
).
Correct Pattern:
function_name(Pattern1) -> Expression1;
function_name(Pattern2) -> Expression2;
function_name(Pattern3) -> Expression3.
To fix this error, replace the incorrect separator with the appropriate one:
- Use semicolons (
;
) between function clauses of the same function - Use a dot (
.
) only after the final clause of a function