-
Notifications
You must be signed in to change notification settings - Fork 28
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
#2420. Add constant pattern exhaustiveness tests #2467
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, with a couple of comments.
/// is defined by the constant type and value. | ||
/// | ||
/// @description Check that if a constant has primitive equality, then its | ||
/// exhaustiveness is defined by the constant type and value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all about using compile-time constant expression evaluation to obtain a compile-time description of the run-time value of an expression, as opposed to relying on the static type of the constant expression.
(This consideration is relevant to an expression whose static type is/contains an extension type, but also a constant expression of type dynamic
.)
So we'd want to make it absolutely unmistakably about the value of the constant expression, not the static type. The next step is that we can inspect that value and determine its (run-time) type. That run-time type is the starting point for the exhaustiveness analysis.
(We can't quite say the same thing about flow analysis, but in this context it's enough to consider exhaustiveness.) So maybe:
/// exhaustiveness is defined by the constant type and value. | |
/// exhaustiveness is defined by the type of the value of the constant. |
/// @description Check that if a constant have no primitive equality then it is | ||
/// not exhausted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might as well stick to the standard phrase which is "has primitive equality" and the negation "does not have primitive equality" (because "has no primitive equality" seems to suggest that it might have one or more of those):
/// @description Check that if a constant have no primitive equality then it is | |
/// not exhausted | |
/// @description Check that if a constant does not have primitive equality | |
/// then it is not exhausted |
/// @description Check that if a constant have no primitive equality then it is | ||
/// not exhausted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar rewrite.
|
||
String test1(bool b) { | ||
switch (b) { | ||
case True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intuitively we should be able to flag this case and the next one as unreachable. However, this implies that the static analysis "knows" that there are no non-bottom, non-extension subtypes of bool
, which may or may not be true.
If we don't get into trouble with any tools (test runners and all) about this unreachability question then it's fine, just keep it. Otherwise we might just drop those two cases because it isn't crucial that we can test impossibilities like that.
Description updated. Please take another look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
2024-01-12 sgrekhov22@gmail.com Fixes dart-lang/co19#2480. Fix typos, add issue numbers (dart-lang/co19#2481) 2024-01-10 sgrekhov22@gmail.com dart-lang/co19#2477. Rename and reorder existing constants tests for match operators before adding new ones (dart-lang/co19#2478) 2024-01-10 sgrekhov22@gmail.com dart-lang/co19#2420. Add null-check-pattern tests for extension types (dart-lang/co19#2475) 2024-01-10 sgrekhov22@gmail.com dart-lang/co19#2119. Add missing experimental flags (dart-lang/co19#2474) 2024-01-10 sgrekhov22@gmail.com dart-lang/co19#2119. Fix typo and improve error messages in Timer tests (dart-lang/co19#2473) 2024-01-09 sgrekhov22@gmail.com Fixes dart-lang/co19#2471. Fix timer constructor tests. Add check for microtasks (dart-lang/co19#2472) 2024-01-09 sgrekhov22@gmail.com Fixes dart-lang/co19#2428. Add `call` member tests for extension types (dart-lang/co19#2438) 2024-01-09 sgrekhov22@gmail.com Fixes dart-lang/co19#2449. Update positions of analyzer expected errors (dart-lang/co19#2450) 2024-01-09 sgrekhov22@gmail.com Fixes dart-lang/co19#2440. Add asyncStart/End() to Stream interface tests (dart-lang/co19#2457) 2024-01-09 sgrekhov22@gmail.com dart-lang/co19#2420. Add another variable pattern exhaustiveness test (dart-lang/co19#2469) 2024-01-08 sgrekhov22@gmail.com dart-lang/co19#2420. Add constant pattern exhaustiveness tests (dart-lang/co19#2467) 2024-01-08 sgrekhov22@gmail.com dart-lang/co19#2436. Add expected constant evaluation error for CFE (dart-lang/co19#2470) 2024-01-08 sgrekhov22@gmail.com dart-lang/co19#2420. Add null-assert pattern exhaustiveness tests (dart-lang/co19#2468) 2024-01-05 sgrekhov22@gmail.com dart-lang/co19#2420. Add parenthesized pattern exhaustiveness tests (dart-lang/co19#2464) Change-Id: I86862732cca7c042120bf312403279c2cc10c135 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345960 Reviewed-by: Alexander Thomas <athom@google.com> Commit-Queue: Erik Ernst <eernst@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
No description provided.