Make reporting of some errors conditional

Change-Id: I4bea35cce9f5d3da425425284c056b7ca228993e
Reviewed-on: https://dart-review.googlesource.com/74668
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart
index e403d5b..17ae919 100644
--- a/pkg/analyzer/lib/error/error.dart
+++ b/pkg/analyzer/lib/error/error.dart
@@ -684,7 +684,6 @@
   StrongModeCode.NOT_INSTANTIATED_BOUND,
   StrongModeCode.TOP_LEVEL_CYCLE,
   StrongModeCode.TOP_LEVEL_FUNCTION_LITERAL_BLOCK,
-  StrongModeCode.TOP_LEVEL_FUNCTION_LITERAL_PARAMETER,
   StrongModeCode.TOP_LEVEL_IDENTIFIER_NO_TYPE,
   StrongModeCode.TOP_LEVEL_INSTANCE_GETTER,
   StrongModeCode.TOP_LEVEL_INSTANCE_METHOD,
diff --git a/pkg/analyzer/lib/src/error/codes.dart b/pkg/analyzer/lib/src/error/codes.dart
index 0a15bc0..f4ff42b 100644
--- a/pkg/analyzer/lib/src/error/codes.dart
+++ b/pkg/analyzer/lib/src/error/codes.dart
@@ -2724,9 +2724,6 @@
  * when appropriate, how the problem can be corrected.
  */
 class StaticTypeWarningCode extends ErrorCode {
-  @override
-  final ErrorSeverity errorSeverity;
-
   /**
    * 12.7 Lists: A fresh instance (7.6.1) <i>a</i>, of size <i>n</i>, whose
    * class implements the built-in class <i>List&lt;E></i> is allocated.
@@ -3375,6 +3372,9 @@
           "The type '{0}' used in the 'for' loop must implement {1} with a "
           "type argument that can be assigned to '{2}'.");
 
+  @override
+  final ErrorSeverity errorSeverity;
+
   /**
    * Initialize a newly created error code to have the given [name]. The message
    * associated with the error will be created from the given [message]
@@ -4936,14 +4936,6 @@
           "The type of the function literal can't be inferred because the literal has a block as its body.",
           correction: "Try adding an explicit type to the variable.");
 
-  static const StrongModeCode TOP_LEVEL_FUNCTION_LITERAL_PARAMETER =
-      const StrongModeCode(
-          ErrorType.HINT,
-          'TOP_LEVEL_FUNCTION_LITERAL_PARAMETER',
-          "The type of '{0}' can't be inferred because the parameter '{1}' does not have an explicit type.",
-          correction:
-              "Try adding an explicit type to the parameter '{1}', or add an explicit type for '{0}'.");
-
   static const StrongModeCode TOP_LEVEL_IDENTIFIER_NO_TYPE = const StrongModeCode(
       ErrorType.HINT,
       'TOP_LEVEL_IDENTIFIER_NO_TYPE',
diff --git a/pkg/analyzer/lib/src/task/strong/checker.dart b/pkg/analyzer/lib/src/task/strong/checker.dart
index 64f7067..74f65da 100644
--- a/pkg/analyzer/lib/src/task/strong/checker.dart
+++ b/pkg/analyzer/lib/src/task/strong/checker.dart
@@ -1935,7 +1935,18 @@
   final CodeChecker _codeChecker;
   final String _name;
 
-  _TopLevelInitializerValidator(this._codeChecker, this._name);
+  /// A flag indicating whether certain diagnostics related to top-level
+  /// elements should be produced. The diagnostics are the ones introduced by
+  /// the analyzer to signal to users when the version of type inference
+  /// performed by the analyzer was unable to accurately infer type information.
+  /// The implementation of type inference used by the task model still has
+  /// these deficiencies, but the implementation used by the driver does not.
+  // TODO(brianwilkerson) Remove this field when the task model has been
+  // removed.
+  final bool flagTopLevel;
+
+  _TopLevelInitializerValidator(this._codeChecker, this._name,
+      {this.flagTopLevel = true});
 
   void validateHasType(AstNode n, PropertyAccessorElement e) {
     if (e.hasImplicitReturnType) {
@@ -1968,7 +1979,7 @@
       if (e is PropertyAccessorElement) {
         if (e.isStatic) {
           validateHasType(n, e);
-        } else if (e.hasImplicitReturnType) {
+        } else if (e.hasImplicitReturnType && flagTopLevel) {
           _codeChecker._recordMessage(
               n, StrongModeCode.TOP_LEVEL_INSTANCE_GETTER, [_name, e.name]);
         }
@@ -1976,7 +1987,7 @@
           e is ExecutableElement &&
           e.kind == ElementKind.METHOD &&
           !e.isStatic) {
-        if (_hasAnyImplicitType(e)) {
+        if (_hasAnyImplicitType(e) && flagTopLevel) {
           _codeChecker._recordMessage(
               n, StrongModeCode.TOP_LEVEL_INSTANCE_METHOD, [_name, e.name]);
         }
@@ -2080,14 +2091,16 @@
     if (method is ExecutableElement) {
       if (method.kind == ElementKind.METHOD &&
           !method.isStatic &&
-          method.hasImplicitReturnType) {
+          method.hasImplicitReturnType &&
+          flagTopLevel) {
         _codeChecker._recordMessage(node,
             StrongModeCode.TOP_LEVEL_INSTANCE_METHOD, [_name, method.name]);
       }
       if (node.typeArguments == null && method.typeParameters.isNotEmpty) {
         if (method.kind == ElementKind.METHOD &&
             !method.isStatic &&
-            _anyParameterHasImplicitType(method)) {
+            _anyParameterHasImplicitType(method) &&
+            flagTopLevel) {
           _codeChecker._recordMessage(node,
               StrongModeCode.TOP_LEVEL_INSTANCE_METHOD, [_name, method.name]);
         }
diff --git a/pkg/analyzer/test/src/task/options_test.dart b/pkg/analyzer/test/src/task/options_test.dart
index 4f0a651..e2a8682 100644
--- a/pkg/analyzer/test/src/task/options_test.dart
+++ b/pkg/analyzer/test/src/task/options_test.dart
@@ -245,7 +245,6 @@
         removeCode(StrongModeCode.NOT_INSTANTIATED_BOUND);
         removeCode(StrongModeCode.TOP_LEVEL_CYCLE);
         removeCode(StrongModeCode.TOP_LEVEL_FUNCTION_LITERAL_BLOCK);
-        removeCode(StrongModeCode.TOP_LEVEL_FUNCTION_LITERAL_PARAMETER);
         removeCode(StrongModeCode.TOP_LEVEL_IDENTIFIER_NO_TYPE);
         removeCode(StrongModeCode.TOP_LEVEL_INSTANCE_GETTER);
         removeCode(StrongModeCode.TOP_LEVEL_INSTANCE_METHOD);