diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart index e403d5b7eb9..17ae919dc34 100644 --- a/pkg/analyzer/lib/error/error.dart +++ b/pkg/analyzer/lib/error/error.dart @@ -684,7 +684,6 @@ const List errorCodeValues = const [ 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 0a15bc0eb27..f4ff42b22bf 100644 --- a/pkg/analyzer/lib/src/error/codes.dart +++ b/pkg/analyzer/lib/src/error/codes.dart @@ -2724,9 +2724,6 @@ class CompileTimeErrorCode extends ErrorCode { * 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) a, of size n, whose * class implements the built-in class List<E> is allocated. @@ -3375,6 +3372,9 @@ class StaticTypeWarningCode extends ErrorCode { "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 @@ class StrongModeCode extends ErrorCode { "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 64f70674fdb..74f65da65d9 100644 --- a/pkg/analyzer/lib/src/task/strong/checker.dart +++ b/pkg/analyzer/lib/src/task/strong/checker.dart @@ -1935,7 +1935,18 @@ class _TopLevelInitializerValidator extends RecursiveAstVisitor { 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 @@ class _TopLevelInitializerValidator extends RecursiveAstVisitor { 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 @@ class _TopLevelInitializerValidator extends RecursiveAstVisitor { 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 @@ class _TopLevelInitializerValidator extends RecursiveAstVisitor { 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 4f0a6517f6e..e2a86820eed 100644 --- a/pkg/analyzer/test/src/task/options_test.dart +++ b/pkg/analyzer/test/src/task/options_test.dart @@ -245,7 +245,6 @@ class ErrorCodeValuesTest { 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);