Skip to content

Commit cb3447f

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer] Fix "yield in non-generator" error reporting.
The analyzer unit tests `YieldEachInNonGeneratorTest.test_async` and `YieldInNonGeneratorTest.test_async` were marked with a `@FailingTest` annotation that claimed that the tests were failing because the parser was trying to parse the yield statement as a binary expression. The actual reason they were failing was because (a) both the analyzer and the shared parser were redundantly flagging the error, resulting in two errors rather than one, and (b) the tests had an incorrect offset and length for the expected error. As a result of these tests being marked with a `@FailingTest` annotation, we had no test coverage of the `YIELD_EACH_IN_NON_GENERATOR` and `YIELD_IN_NON_GENERATOR` errors. I've resolved the redundancy by suppressing the error from the parser and keeping the analyzer's logic to flag the error, since the analyzer's logic produces a more specific error (it correctly distinguishes between `YIELD_EACH_IN_NON_GENERATOR` and `YIELD_IN_NON_GENERATOR`, whereas the shared parser does not). And I've updated the tests with the correct offset and length for the expected error. So the tests no longer fail and test coverage is restored. Change-Id: Ibbee3329d4699d7e78bec964303e9c9b239f0b8b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400140 Auto-Submit: Paul Berry <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 023473d commit cb3447f

File tree

3 files changed

+3
-13
lines changed

3 files changed

+3
-13
lines changed

pkg/analyzer/lib/src/fasta/error_converter.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,7 @@ class FastaErrorReporter {
504504
);
505505
return;
506506
case "YIELD_IN_NON_GENERATOR":
507-
errorReporter?.atOffset(
508-
offset: offset,
509-
length: length,
510-
errorCode: CompileTimeErrorCode.YIELD_IN_NON_GENERATOR,
511-
);
507+
// Reported by [YieldStatementResolver._resolve_notGenerator]
512508
return;
513509
case "BUILT_IN_IDENTIFIER_IN_DECLARATION":
514510
// Reported by [ErrorVerifier._checkForBuiltInIdentifierAsName].

pkg/analyzer/test/src/diagnostics/yield_each_in_non_generator_test.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ main() {
1515

1616
@reflectiveTest
1717
class YieldEachInNonGeneratorTest extends PubPackageResolutionTest {
18-
@FailingTest(
19-
reason: 'We are currently trying to parse the yield statement as a '
20-
'binary expression.')
2118
test_async() async {
2219
await assertErrorsInCode(r'''
2320
f() async {
2421
yield* 0;
2522
}
2623
''', [
27-
error(CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR, 0, 0),
24+
error(CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR, 14, 9),
2825
]);
2926
}
3027

pkg/analyzer/test/src/diagnostics/yield_in_non_generator_test.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ main() {
1515

1616
@reflectiveTest
1717
class YieldInNonGeneratorTest extends PubPackageResolutionTest {
18-
@FailingTest(
19-
reason: 'We are currently trying to parse the yield statement as a '
20-
'binary expression.')
2118
test_async() async {
2219
await assertErrorsInCode(r'''
2320
f() async {
2421
yield 0;
2522
}
2623
''', [
27-
error(CompileTimeErrorCode.YIELD_IN_NON_GENERATOR, 0, 0),
24+
error(CompileTimeErrorCode.YIELD_IN_NON_GENERATOR, 14, 8),
2825
]);
2926
}
3027

0 commit comments

Comments
 (0)