-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Enhanced enums: incorrect missing case clause analyzer warning #49188
Comments
Bug: #49188 Change-Id: Ie23327fe813de45b2ad63d25f038d070de243d53 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247421 Reviewed-by: Samuel Rawlins <srawlins@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
The code example is missing enum E {
a, b;
static final data = "I'm not a real enum member";
static const moreData = 'Neither am I';
String get name {
switch(this) {
case E.a:
return 'AAAA';
case E.b:
return 'BBBB';
}
}
} |
@mono0926 Thanks for the input. The issue is not that the code doesn't run, but rather about an incorrect analyzer warning about missing case clauses for |
I think I understand your intention. enum E {
a, b;
String get name {
switch(this) {
case a: // `E.a` is correct
return 'AAAA';
case b: // `E.b` is correct
return 'BBBB';
}
}
} |
Ah sorry, now I understand what you mean. Just to be clear, I don't think it's the sample code that is incorrect: inside the enum definition, |
Yes, the fix covers exactly this issue - understanding of usage of just simple identifiers in |
Bug: #49188 Change-Id: I01ab5bb0cb279f40ce3c7917720e1232e00fddea
This is a patch release that fixes: - Improve analysis of enums and switch (issue [#49188]). - Fix compiler crash when initializing Finalizable objects (issue [#49075]). [#49188]: #49188 [#49075]: #49075 Change-Id: If2059474ce2acbadf7f3c6e407f0087d262e2842 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/249161 Reviewed-by: Michael Thomsen <mit@google.com>
I've confirmed that this bug has been fixed in Dart 2.17.5 included with the latest stable v3.0.3 of Flutter, and that the code of #49188 (comment) works fine without any warnings. DartPad: https://dartpad.dev/?id=caa4217a7363edd4b8ea3299cbdfdc48 |
Thank you for the confirmation. |
Confirmation from here too. Thanks for the quick fix! |
EDIT: It appears this has been fixed in Dart 2.19, sorry for the confusion. @scheglov Hate to say but I don't think this is fixed: enum E {
a, b;
static final data = "I'm not a real enum member";
static const moreData = 'Neither am I';
// NEW CODE
static const otherData = E.a; // not a new entry in E
String get name {
switch(this) {
case E.a:
return 'AAAA';
case E.b:
return 'BBBB';
}
}
} In this case, the analyzer doesn't complain, but the code doesn't compile on Dart 2.18.6 either:
It's worth noting that adding |
Thanks for checking @Levi-Lesches . Confirmed on https://dartpad.dev/?channel=beta. The code analyzes cleanly and compiles. |
The analyzer raises the warning
missing_enum_constant_in_switch
for the code below, sayingMissing case clause for 'data'
and similarly formoreData
. Of course, they shouldn't have case clauses.(Dart SDK version: 2.17.1 (stable))
The text was updated successfully, but these errors were encountered: