Fix message of RETURN_IN_GENERATOR; stop double reporting.

* This message should only be reported by the parser; the
  error raised in the analyzer was strictly duplicate.
* This message theoretically used to mention "async*" or
  "sync*" depending on the modifier that the function in
  question listed. However, listing one modifier or the
  other is a red herring, and may confuse the user; any
  function declared with one or the other is a "generator",
  and the error applies equally to a "generator" using one
  or the other modifier.

Bug: https://github.com/dart-lang/sdk/issues/43665
Change-Id: I6ef1f5c055473170e7563222f6f0a6c56a4ad5f5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210801
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Sam Rawlins 2021-08-24 01:43:48 +00:00 committed by commit-bot@chromium.org
parent f4b6fa85ea
commit 419d70afb2
7 changed files with 11 additions and 26 deletions

View file

@ -12011,8 +12011,7 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
hasPublishedDocs: true);
/**
* Parameters:
* 0: the modifier that makes the function a generator
* No parameters.
*/
// #### Description
//
@ -12053,10 +12052,13 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
// ```
static const CompileTimeErrorCode RETURN_IN_GENERATOR = CompileTimeErrorCode(
'RETURN_IN_GENERATOR',
"Can't return a value from a generator function (using the '{0}' "
"modifier).",
correction: "Try removing the value, replacing 'return' with 'yield' or "
"changing the method body modifier.",
"Can't return a value from a generator function that uses the 'async*' "
"or 'sync*' modifier.",
// TODO(srawlins): Splitting this code into two cases, one for block-
// bodied, and one for expression-bodied, would improve each correction
// message. This split would have to be done in the parser.
correction: "Try replacing 'return' with 'yield', using a block function "
"body, or changing the method body modifier.",
hasPublishedDocs: true);
/**

View file

@ -62,13 +62,6 @@ class ReturnTypeVerifier {
}
if (enclosingExecutable.isGenerator) {
if (expression != null) {
_errorReporter.reportErrorForNode(
CompileTimeErrorCode.RETURN_IN_GENERATOR,
statement,
[enclosingExecutable.isAsynchronous ? 'async*' : 'sync*'],
);
}
return;
}

View file

@ -267,10 +267,7 @@ class FastaErrorReporter {
return;
case "RETURN_IN_GENERATOR":
errorReporter?.reportErrorForOffset(
CompileTimeErrorCode.RETURN_IN_GENERATOR, offset, length,
// TODO(danrubel): Update the parser to report the modifier
// involved in this error... either async* or sync*
['async*']);
CompileTimeErrorCode.RETURN_IN_GENERATOR, offset, length);
return;
case "SUPER_IN_REDIRECTING_CONSTRUCTOR":
errorReporter?.reportErrorForOffset(

View file

@ -29,7 +29,6 @@ f() async* {
return 0;
}
''', [
error(CompileTimeErrorCode.RETURN_IN_GENERATOR, 15, 9),
error(CompileTimeErrorCode.RETURN_IN_GENERATOR, 15, 6),
]);
}
@ -64,7 +63,6 @@ f() sync* {
return 0;
}
''', [
error(CompileTimeErrorCode.RETURN_IN_GENERATOR, 14, 9),
error(CompileTimeErrorCode.RETURN_IN_GENERATOR, 14, 6),
]);
}

View file

@ -11393,7 +11393,8 @@ class C {
### return_in_generator
_Can't return a value from a generator function (using the '{0}' modifier)._
_Can't return a value from a generator function that uses the 'async*' or
'sync*' modifier._
#### Description

View file

@ -56,8 +56,6 @@ Iterable<int> foo8() sync* {
//^^^^^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_IN_GENERATOR
// [cfe] 'sync*' and 'async*' can't return a value.
//^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_IN_GENERATOR
}
Stream<int> foo9() async* {
@ -67,8 +65,6 @@ Stream<int> foo9() async* {
//^^^^^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_IN_GENERATOR
// [cfe] 'sync*' and 'async*' can't return a value.
//^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_IN_GENERATOR
}
test() async {

View file

@ -60,7 +60,6 @@ Iterable<int> foo8() sync* {
//^^^^^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_IN_GENERATOR
//^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_IN_GENERATOR
// [cfe] 'sync*' and 'async*' can't return a value.
}
@ -71,7 +70,6 @@ Stream<int> foo9() async* {
//^^^^^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_IN_GENERATOR
//^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_IN_GENERATOR
// [cfe] 'sync*' and 'async*' can't return a value.
}