Updates status file to expect MissingCompileTimeError for illegal
async function return type check whenever running in 'legacy mode'.

Adapts language_2_kernel.status such that a MissingCompileTimeError is
expected for illegal return types of async functions when running in
'legacy mode'. Updates the commentary in finishFunction in
body_builder.dart.

Some legacy tests* have revealed that it may not always be correct to
check whether [strongMode] is enabled before checking the return type of
async functions. The reason behind the strongMode check was to ensure
that [_typeInferrer.typeSchemaEnvironment] would be instantiated as
per ahe's suggestion.

There seems to be some inconsistency in the code base as to when
[_typeInferrer.typeSchemaEnvironment] is non-null. For example, during
the fasta perf benchmarks one may observe a null value, whilst it
seems that the member is always non-null when running `dart
--no-preview-dart-2 <script.dart>`.

* test log: https://ci.chromium.org/p/dart/builders/luci.dart.ci.sandbox/front-end-legacy-linux-release-x64/621

Change-Id: I2211bfe0ae75a7aa35e2d698ff5cba27af484d07
Bug: 33425
Reviewed-on: https://dart-review.googlesource.com/69920
Commit-Queue: Daniel Hillerström <hillerstrom@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
index 3e3d547..e317122 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -708,11 +708,16 @@
 
     // For async functions with declared return types, we need to determine
     // whether those types are valid.
-    // TODO(hillerstrom): currently we need to check whether strongMode is
-    // enabled (or rather that we are not running in 'legacy mode') otherwise
-    // [_typeInferrer.typeSchemaEnvironment] might be null. We should remove this
-    // check once Dart 1 supported has been dropped.
-    if (library.loader.target.strongMode &&
+
+    // TODO(hillerstrom): currently, we need to check whether [strongMode] is
+    // enabled for two reasons:
+    // 1) the [isSubtypeOf] predicate produces false-negatives when [strongMode]
+    // is false.
+    // 2) the member [_typeInferrer.typeSchemaEnvironment] might be null when
+    // [strongMode] is false. This particular behaviour can be observed when
+    // running the fasta perf benchmarks.
+    bool strongMode = library.loader.target.strongMode;
+    if (strongMode &&
         builder.returnType != null &&
         asyncModifier == AsyncMarker.Async) {
       DartType returnType = builder.function.returnType;
@@ -726,7 +731,8 @@
         // TODO(hillerstrom): once types get annotated with location
         // information, we can improve the quality of the error message by
         // using the offset of [returnType].
-        addProblem(fasta.messageIllegalAsyncReturnType, member.charOffset, 0);
+        addProblem(fasta.messageIllegalAsyncReturnType, member.charOffset,
+            member.name.length);
       }
     }
 
diff --git a/tests/language_2/language_2_kernel.status b/tests/language_2/language_2_kernel.status
index e0fbf0b..1c6f262 100644
--- a/tests/language_2/language_2_kernel.status
+++ b/tests/language_2/language_2_kernel.status
@@ -1549,7 +1549,9 @@
 async_congruence_method_test/01: MissingCompileTimeError
 async_congruence_unnamed_test/01: MissingCompileTimeError
 async_congruence_unnamed_test/02: MissingCompileTimeError
+async_or_generator_return_type_stacktrace_test/01: MissingCompileTimeError
 async_return_types_test/tooManyTypeParameters: MissingCompileTimeError
+async_return_types_test/wrongReturnType: MissingCompileTimeError
 async_return_types_test/wrongTypeParameter: MissingCompileTimeError
 bad_named_parameters2_test/01: MissingCompileTimeError
 bad_named_parameters_test/01: MissingCompileTimeError