-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Test language_2/void_type_usage_test.dart not discriminating closely enough #31883
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
Comments
We should probably also test that I also have tests for some other things; depending on how conclusive we want to be:
These may be overkill; however; these were cases that I wrote before implementing them in the analyzer, where each has a different path. |
Thanks for the input! We should indeed check those things, they are justified both from a black-box perspective ("this kind of expression exists, we should test it") and a white-box perspective ("if this is omitted, some code in the analyzer never gets tested"). |
Also, in line 95: Looks to me like the first line was supposed to be |
OK another suggestion regarding either the test or the spec; Should
If I'm not mistaken, In then gives an example which is incomplete: "for (e1; e2; e3) {..}, e1 and e3 may have type void." I'm assuming that this is an error in the informal spec rather than an error in the test (which seems to have very thoroughly tested that |
Good catch, there's definitely no point in having the same test twice! I believe the most meaningful fix is to change line 95 to |
Here's the CL which changes lines 95 and 102 as mentioned. |
About |
Cleanup occurs here: https://dart-review.googlesource.com/350921. This CL changes However, the CL also changes a rather large number of other things. In particular, the old multi-test had several duplicated labels, which means that some tests could fail (due to a missing compile-time error) and it would never be detected, as long as just one of the cases with the duplicated label would gave rise to a compile-time error. This fault has been removed (automatically) because of the switch to the new error expectation syntax, but it does imply that the version of the test which is introduced by this PR will cause the CFE and the analyzer to fail with about 130 missing compile-time errors each. |
Implementation of the missing compile-time errors is handled in #54889. |
The old version of language/void/void_type_usage_test.dart had some faults (compile-time errors were expected, but they weren't reported by tools and yet the test run succeeded). The failures were caused by some amount of duplication in the labels (a handful of duplicate labels from a set of about 450 labels, that is, it wasn't immediately obvious). This CL updates the test to use the new test expectation syntax (`// ^^^^`) and adjusts the expectations to match the currently reported error messages, plus the ones about `void` that are missing. Note that this test went through a phase where I believed that we had about 260 failures (130 CFE and 130 analyzer), but they turned out to be a consequence of migrating this test incorrectly from being a multi test into a form where it uses the current test expectation comments (`// ^^^` and such). At this point we just have 3 failures (all on expressions of the form `e += 1`), all with the CFE. Bug: #31883 Change-Id: Ib1ceb56326a5847e3ca23ac0ee655eee65f0d76f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350921 Reviewed-by: Nate Bosch <[email protected]> Commit-Queue: Erik Ernst <[email protected]>
The test
language_2/void_type_usage_test.dart
does not discriminate with sufficient precision, which means that it may seem to succeed by having a compile-time error (for the about 200 subtests with expected outcome//# compile-time error
), but the static analysis still may not have detected the intended fault in the source code.For instance, the subtest
param_plus_eq
is intended to verify that the following statement is a compile-time error, wherex
is a variable of typevoid
:This is a compile-time error because the value of the expression
x
is used in a non-trivial manner (we have about 6 specific situations where such a value can be used, and this is not one of them), but it is also a compile-time error because the typevoid
does not have anoperator +
, which is required for+=
. So it may seem to succeed, but the error may still not be the desired one.Similarly, the following is a compile-time error because the expression
x
of typevoid
cannot be evaluated to serve as the condition for awhile
statement:Given that
void
is a top type (likeObject
anddynamic
), it should be allowed to have such a condition of typevoid
and implicitly downcast it tobool
as needed forwhile
, and the statement should then be OK, except for the fact that it uses the value ofx
at all. However, the test currently succeeds withdartanalyzer --strong
because there is a compile-time error --- but the error says "Conditions must have a static type of 'bool'" rather than something like "The value of an expression of typevoid
can only be used in 6 specific situations listed in generalized-void.md". ;-)All in all, this means that in a number of subtests,
language_2/void_type_usage_test.dart
does not currently discriminate between some right and wrong reasons for succeeding with outcomecompile-time error
, and this might justify a different approach (e.g., something like the "unit tests" used for testing dart2js, where it is possible to check that a specific error is emitted).The text was updated successfully, but these errors were encountered: