Skip to content

Commit 926d4e1

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Use new DiagnosticCode name in some directories - 2
Work towards #60635 Change-Id: I1d36abb9f98ae875697ac54b9e493ffdb8666f75 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425580 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent c5116b4 commit 926d4e1

16 files changed

+108
-99
lines changed

pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class BinaryExpressionResolver {
8585
}) {
8686
_resolver.boolExpressionVerifier.checkForNonBoolExpression(
8787
operand,
88-
errorCode: CompileTimeErrorCode.NON_BOOL_OPERAND,
88+
diagnosticCode: CompileTimeErrorCode.NON_BOOL_OPERAND,
8989
arguments: [operator],
9090
whyNotPromoted: whyNotPromoted,
9191
);

pkg/analyzer/lib/src/diagnostic/diagnostic_factory.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class DiagnosticFactory {
4646
/// Return a diagnostic indicating that [duplicateElement] reuses a name
4747
/// already used by [originalElement].
4848
AnalysisError duplicateDefinition(
49-
ErrorCode code,
49+
DiagnosticCode code,
5050
Element duplicateElement,
5151
Element originalElement,
5252
List<Object> arguments,
@@ -77,7 +77,7 @@ class DiagnosticFactory {
7777
/// already used by [originalNode].
7878
AnalysisError duplicateDefinitionForNodes(
7979
Source source,
80-
ErrorCode code,
80+
DiagnosticCode code,
8181
SyntacticEntity duplicateNode,
8282
SyntacticEntity originalNode,
8383
List<Object> arguments,
@@ -314,7 +314,7 @@ class DiagnosticFactory {
314314
/// [superMember].
315315
AnalysisError invalidOverride(
316316
Source source,
317-
ErrorCode errorCode,
317+
DiagnosticCode code,
318318
SyntacticEntity errorNode,
319319
ExecutableElement member,
320320
ExecutableElement superMember,
@@ -328,7 +328,7 @@ class DiagnosticFactory {
328328
source: source,
329329
offset: errorNode.offset,
330330
length: errorNode.length,
331-
errorCode: errorCode,
331+
errorCode: code,
332332
arguments: [
333333
memberName,
334334
member.enclosingElement2!.name3,
@@ -342,15 +342,15 @@ class DiagnosticFactory {
342342
// INVALID_IMPLEMENTATION_OVERRIDE may provide the subclass as superMember
343343
// if the subclass has an abstract member and the superclass has the
344344
// concrete).
345-
if (errorCode == CompileTimeErrorCode.INVALID_OVERRIDE)
345+
if (code == CompileTimeErrorCode.INVALID_OVERRIDE)
346346
DiagnosticMessageImpl(
347347
filePath: superFragment.libraryFragment!.source.fullName,
348348
message: "The member being overridden.",
349349
offset: superFragment.nameOffset2 ?? -1,
350350
length: superFragment.name2!.length,
351351
url: null,
352352
),
353-
if (errorCode == CompileTimeErrorCode.INVALID_OVERRIDE_SETTER)
353+
if (code == CompileTimeErrorCode.INVALID_OVERRIDE_SETTER)
354354
DiagnosticMessageImpl(
355355
filePath: superFragment.libraryFragment!.source.fullName,
356356
message: "The setter being overridden.",

pkg/analyzer/lib/src/error/best_practices_verifier.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,23 +1087,23 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
10871087

10881088
void _checkForInvariantNanComparison(BinaryExpression node) {
10891089
void reportStartEnd(
1090-
ErrorCode errorCode,
1090+
DiagnosticCode diagnosticCode,
10911091
SyntacticEntity startEntity,
10921092
SyntacticEntity endEntity,
10931093
) {
10941094
var offset = startEntity.offset;
10951095
_errorReporter.atOffset(
10961096
offset: offset,
10971097
length: endEntity.end - offset,
1098-
errorCode: errorCode,
1098+
errorCode: diagnosticCode,
10991099
);
11001100
}
11011101

1102-
void checkLeftRight(ErrorCode errorCode) {
1102+
void checkLeftRight(DiagnosticCode diagnosticCode) {
11031103
if (node.leftOperand.isDoubleNan) {
1104-
reportStartEnd(errorCode, node.leftOperand, node.operator);
1104+
reportStartEnd(diagnosticCode, node.leftOperand, node.operator);
11051105
} else if (node.rightOperand.isDoubleNan) {
1106-
reportStartEnd(errorCode, node.operator, node.rightOperand);
1106+
reportStartEnd(diagnosticCode, node.operator, node.rightOperand);
11071107
}
11081108
}
11091109

pkg/analyzer/lib/src/error/bool_expression_verifier.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,17 @@ class BoolExpressionVerifier {
4040
}) {
4141
checkForNonBoolExpression(
4242
condition,
43-
errorCode: CompileTimeErrorCode.NON_BOOL_CONDITION,
43+
diagnosticCode: CompileTimeErrorCode.NON_BOOL_CONDITION,
4444
whyNotPromoted: whyNotPromoted,
4545
);
4646
}
4747

4848
/// Verify that the given [expression] is of type 'bool', and report
49-
/// [errorCode] if not, or a nullability error if its improperly nullable.
49+
/// [diagnosticCode] if not, or a nullability error if its improperly
50+
/// nullable.
5051
void checkForNonBoolExpression(
5152
Expression expression, {
52-
required ErrorCode errorCode,
53+
required DiagnosticCode diagnosticCode,
5354
List<Object> arguments = const [],
5455
required Map<SharedTypeView, NonPromotionReason> Function()? whyNotPromoted,
5556
}) {
@@ -71,7 +72,7 @@ class BoolExpressionVerifier {
7172
),
7273
);
7374
} else {
74-
_errorReporter.atNode(expression, errorCode, arguments: arguments);
75+
_errorReporter.atNode(expression, diagnosticCode, arguments: arguments);
7576
}
7677
}
7778
}
@@ -83,7 +84,7 @@ class BoolExpressionVerifier {
8384
}) {
8485
checkForNonBoolExpression(
8586
expression,
86-
errorCode: CompileTimeErrorCode.NON_BOOL_NEGATION_EXPRESSION,
87+
diagnosticCode: CompileTimeErrorCode.NON_BOOL_NEGATION_EXPRESSION,
8788
whyNotPromoted: whyNotPromoted,
8889
);
8990
}

pkg/analyzer/lib/src/error/correct_override.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class CorrectOverrideHelper {
4545
required ExecutableElement2OrMember superMember,
4646
required ErrorReporter errorReporter,
4747
required SyntacticEntity errorNode,
48-
required ErrorCode errorCode,
48+
required DiagnosticCode diagnosticCode,
4949
}) {
5050
var isCorrect = isCorrectOverrideOf(superMember: superMember);
5151
if (!isCorrect) {
@@ -55,7 +55,7 @@ class CorrectOverrideHelper {
5555
errorReporter.reportError(
5656
_diagnosticFactory.invalidOverride(
5757
errorReporter.source,
58-
errorCode,
58+
diagnosticCode,
5959
errorNode,
6060
_thisMember,
6161
superMember,

pkg/analyzer/lib/src/error/dead_code_verifier.dart

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
1717
import 'package:analyzer/src/dart/resolver/scope.dart';
1818
import 'package:analyzer/src/error/codes.dart';
1919

20-
typedef _CatchClausesVerifierReporter =
21-
void Function(
22-
CatchClause first,
23-
CatchClause last,
24-
ErrorCode,
25-
List<Object> arguments,
26-
);
27-
2820
/// State information captured by [NullSafetyDeadCodeVerifier.for_conditionEnd]
2921
/// for later use by [NullSafetyDeadCodeVerifier.for_updaterBegin].
3022
class DeadCodeForPartsState {
@@ -150,7 +142,7 @@ class DeadCodeVerifier extends RecursiveAstVisitor<void> {
150142
library,
151143
);
152144
NodeList<SimpleIdentifier> names;
153-
ErrorCode warningCode;
145+
DiagnosticCode warningCode;
154146
if (combinator is HideCombinator) {
155147
names = combinator.hiddenNames;
156148
warningCode = WarningCode.UNDEFINED_HIDDEN_NAME;
@@ -525,15 +517,21 @@ class _BreakDoStatementVisitor extends RecursiveAstVisitor<void> {
525517

526518
class _CatchClausesVerifier {
527519
final TypeSystemImpl _typeSystem;
528-
final _CatchClausesVerifierReporter _errorReporter;
520+
final void Function(
521+
CatchClause first,
522+
CatchClause last,
523+
DiagnosticCode,
524+
List<Object> arguments,
525+
)
526+
_reportDiagnostic;
529527
final List<CatchClause> catchClauses;
530528

531529
bool _done = false;
532530
final List<TypeImpl> _visitedTypes = [];
533531

534532
_CatchClausesVerifier(
535533
this._typeSystem,
536-
this._errorReporter,
534+
this._reportDiagnostic,
537535
this.catchClauses,
538536
);
539537

@@ -545,7 +543,7 @@ class _CatchClausesVerifier {
545543
if (currentType == null || currentType.isDartCoreObject) {
546544
if (catchClause != catchClauses.last) {
547545
var index = catchClauses.indexOf(catchClause);
548-
_errorReporter(
546+
_reportDiagnostic(
549547
catchClauses[index + 1],
550548
catchClauses.last,
551549
WarningCode.DEAD_CODE_CATCH_FOLLOWING_CATCH,
@@ -560,7 +558,7 @@ class _CatchClausesVerifier {
560558
// subtype of a previous on-catch exception type.
561559
for (var type in _visitedTypes) {
562560
if (_typeSystem.isSubtypeOf(currentType, type)) {
563-
_errorReporter(
561+
_reportDiagnostic(
564562
catchClause,
565563
catchClauses.last,
566564
WarningCode.DEAD_CODE_ON_CATCH_SUBTYPE,

pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class DuplicateDefinitionVerifier {
301301
return;
302302
}
303303

304-
ErrorCode getError(Element previous, Element current) {
304+
DiagnosticCode getDiagnostic(Element previous, Element current) {
305305
if (previous is FieldFormalParameterElement &&
306306
current is FieldFormalParameterElement) {
307307
return CompileTimeErrorCode.DUPLICATE_FIELD_FORMAL_PARAMETER;
@@ -316,7 +316,7 @@ class DuplicateDefinitionVerifier {
316316
_reportedTokens.add(identifier);
317317
_errorReporter.reportError(
318318
_diagnosticFactory.duplicateDefinition(
319-
getError(previous, element),
319+
getDiagnostic(previous, element),
320320
element,
321321
previous,
322322
[lookupName],
@@ -332,7 +332,7 @@ class DuplicateDefinitionVerifier {
332332
_reportedTokens.add(identifier);
333333
_errorReporter.reportError(
334334
_diagnosticFactory.duplicateDefinition(
335-
getError(previous, element),
335+
getDiagnostic(previous, element),
336336
element,
337337
previous,
338338
[lookupName],

pkg/analyzer/lib/src/error/ignore_validator.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class IgnoreValidator {
2020
/// Error codes used to report `unnecessary_ignore`s.
2121
/// These codes are set when the `UnnecessaryIgnore` lint rule is instantiated and
2222
/// registered by the linter.
23-
static late ErrorCode unnecessaryIgnoreLocationLintCode;
24-
static late ErrorCode unnecessaryIgnoreFileLintCode;
25-
static late ErrorCode unnecessaryIgnoreNameLocationLintCode;
26-
static late ErrorCode unnecessaryIgnoreNameFileLintCode;
23+
static late DiagnosticCode unnecessaryIgnoreLocationLintCode;
24+
static late DiagnosticCode unnecessaryIgnoreFileLintCode;
25+
static late DiagnosticCode unnecessaryIgnoreNameLocationLintCode;
26+
static late DiagnosticCode unnecessaryIgnoreNameFileLintCode;
2727

2828
/// The error reporter to which errors are to be reported.
2929
final ErrorReporter _errorReporter;
@@ -260,7 +260,7 @@ class IgnoreValidator {
260260
}
261261
}
262262

263-
late ErrorCode lintCode;
263+
late DiagnosticCode lintCode;
264264
if (forFile) {
265265
lintCode =
266266
diagnosticsOnLine > 1

pkg/analyzer/lib/src/error/inheritance_override.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ class _ClassVerifier {
354354
superMember: interfaceElement,
355355
errorReporter: reporter,
356356
errorNode: classNameToken,
357-
errorCode:
357+
diagnosticCode:
358358
concreteElement is SetterElement2OrMember
359359
? CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE_SETTER
360360
: CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE,
@@ -408,7 +408,7 @@ class _ClassVerifier {
408408
superMember: superMember.asElement2,
409409
errorReporter: reporter,
410410
errorNode: node,
411-
errorCode:
411+
diagnosticCode:
412412
member is SetterElement
413413
? CompileTimeErrorCode.INVALID_OVERRIDE_SETTER
414414
: CompileTimeErrorCode.INVALID_OVERRIDE,
@@ -481,7 +481,10 @@ class _ClassVerifier {
481481

482482
/// Verify that the given [namedType] does not extend, implement, or mixes-in
483483
/// types such as `num` or `String`.
484-
bool _checkDirectSuperTypeNode(NamedType namedType, ErrorCode errorCode) {
484+
bool _checkDirectSuperTypeNode(
485+
NamedType namedType,
486+
DiagnosticCode diagnosticCode,
487+
) {
485488
if (namedType.isSynthetic) {
486489
return false;
487490
}
@@ -496,7 +499,7 @@ class _ClassVerifier {
496499
);
497500
},
498501
notSubtypable: () {
499-
reporter.atNode(namedType, errorCode, arguments: [type]);
502+
reporter.atNode(namedType, diagnosticCode, arguments: [type]);
500503
},
501504
);
502505
}
@@ -746,7 +749,7 @@ class _ClassVerifier {
746749

747750
/// Return the error code that should be used when the given class [element]
748751
/// references itself directly.
749-
ErrorCode _getRecursiveErrorCode(InterfaceElement element) {
752+
DiagnosticCode _getRecursiveErrorCode(InterfaceElement element) {
750753
if (element.supertype?.element3 == classElement.asElement2) {
751754
return CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_EXTENDS;
752755
}

pkg/analyzer/lib/src/error/nullable_dereference_verifier.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,36 @@ class NullableDereferenceVerifier {
3131
_resolver = resolver;
3232

3333
bool expression(
34-
ErrorCode errorCode,
34+
DiagnosticCode diagnosticCode,
3535
Expression expression, {
3636
DartType? type,
3737
}) {
3838
type ??= expression.typeOrThrow;
39-
return _check(errorCode, expression, type);
39+
return _check(diagnosticCode, expression, type);
4040
}
4141

4242
void report(
43-
ErrorCode errorCode,
43+
DiagnosticCode diagnosticCode,
4444
SyntacticEntity errorEntity,
4545
DartType receiverType, {
4646
List<String> arguments = const <String>[],
4747
List<DiagnosticMessage>? messages,
4848
}) {
4949
if (receiverType == _typeSystem.typeProvider.nullType) {
50-
errorCode = CompileTimeErrorCode.INVALID_USE_OF_NULL_VALUE;
50+
diagnosticCode = CompileTimeErrorCode.INVALID_USE_OF_NULL_VALUE;
5151
arguments = [];
5252
}
5353
if (errorEntity is AstNode) {
5454
_errorReporter.atNode(
5555
errorEntity,
56-
errorCode,
56+
diagnosticCode,
5757
arguments: arguments,
5858
contextMessages: messages,
5959
);
6060
} else if (errorEntity is Token) {
6161
_errorReporter.atToken(
6262
errorEntity,
63-
errorCode,
63+
diagnosticCode,
6464
arguments: arguments,
6565
contextMessages: messages,
6666
);
@@ -75,7 +75,11 @@ class NullableDereferenceVerifier {
7575
/// receiver is the implicit `this`, the name of the invocation.
7676
///
7777
/// Returns whether [receiverType] was reported.
78-
bool _check(ErrorCode errorCode, AstNode errorNode, DartType receiverType) {
78+
bool _check(
79+
DiagnosticCode diagnosticCode,
80+
AstNode errorNode,
81+
DartType receiverType,
82+
) {
7983
if (receiverType is DynamicType ||
8084
receiverType is InvalidType ||
8185
!_typeSystem.isPotentiallyNullable(receiverType)) {
@@ -89,7 +93,7 @@ class NullableDereferenceVerifier {
8993
_resolver.flowAnalysis.flow?.whyNotPromoted(errorNode)(),
9094
);
9195
}
92-
report(errorCode, errorNode, receiverType, messages: messages);
96+
report(diagnosticCode, errorNode, receiverType, messages: messages);
9397
return true;
9498
}
9599
}

0 commit comments

Comments
 (0)