avoid_empty_else
Empty statements are not allowed in an 'else' clause.
Description
#The analyzer produces this diagnostic when the statement after an else
is an empty statement (a semicolon).
For more information, see the documentation for avoid_empty_else
.
Example
#The following code produces this diagnostic because the statement following the else
is an empty statement:
void f(int x, int y) {
if (x > y)
print("1");
else ;
print("2");
}
Common fixes
#If the statement after the empty statement is intended to be executed only when the condition is false
, then remove the empty statement:
void f(int x, int y) {
if (x > y)
print("1");
else
print("2");
}
If there is no code that is intended to be executed only when the condition is false
, then remove the whole else
clause:
void f(int x, int y) {
if (x > y)
print("1");
print("2");
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.