mirror of
https://github.com/dart-lang/sdk
synced 2024-09-20 15:21:19 +00:00
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>
This commit is contained in:
parent
e6a9551e58
commit
c28db2d6e1
|
@ -684,7 +684,6 @@ const List<ErrorCode> 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,
|
||||
|
|
|
@ -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) <i>a</i>, of size <i>n</i>, whose
|
||||
* class implements the built-in class <i>List<E></i> 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',
|
||||
|
|
|
@ -1935,7 +1935,18 @@ class _TopLevelInitializerValidator extends RecursiveAstVisitor<Null> {
|
|||
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<Null> {
|
|||
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<Null> {
|
|||
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<Null> {
|
|||
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]);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue