Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dart: do not generate default clause for enumerations #1641

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

pwrobeldev
Copy link
Contributor

----- Motivation -----
In the case of enumerations we match all the possible
matchable values in case clauses. Then, we generate
default clause, but the linter is able to see, that
this is a dead code.

In such case unreachable_switch_default warning is
raised by the linter.

----- Important -----
The above is true if we generate an authentic enum in Dart.
In the case when aliasing enumerators are needed, then
we generate an enum-like class. In such case default clause
is needed, because we operate on integers and compiler assumes,
that switch-case is not exhaustive.

----- Implemented solution -----
Removed generation of redundant default clause when we use
an authentic Dart enum to avoid linter warnings.

----- Motivation -----
In the case of enumerations we match all the possible
matchable values in `case` clauses. Then, we generate
`default` clause, but the linter is able to see, that
this is a dead code.

In such case `unreachable_switch_default` warning is
raised by the linter.

----- Important -----
The above is true if we generate an authentic `enum` in Dart.
In the case when aliasing enumerators are needed, then
we generate an enum-like class. In such case `default` clause
is needed, because we operate on integers and compiler assumes,
that switch-case is not exhaustive.

----- Implemented solution -----
Removed generation of redundant `default` clause when we use
an authentic Dart `enum` to avoid linter warnings.

Signed-off-by: Patryk Wrobel <[email protected]>
This change adjusts the expected output of smoke tests.
The redundant 'default' section is removed for authentic
Dart enumerations.

Signed-off-by: Patryk Wrobel <[email protected]>
Signed-off-by: Patryk Wrobel <[email protected]>
@pwrobeldev
Copy link
Contributor Author

pwrobeldev commented Dec 18, 2024

Dart SDK issue and code, which introduced the check for default clause. The issue reported the missing warning and introduced it. Links can be found here:

Diagnostic message description:

@pwrobeldev pwrobeldev marked this pull request as ready for review December 18, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant