Skip to content

Commit 74a5794

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Rename "error" variables to be "diagnostics"
This is cleanup from renaming types like `DiagnosticCode`. I found these variables which also need to be renamed. Change-Id: I0e6d0633009c9c2b5d719f4c911295f9ded4e257 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/468160 Auto-Submit: Samuel Rawlins <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent 42e7de8 commit 74a5794

19 files changed

+127
-135
lines changed

pkg/analyzer/lib/src/analysis_options/options_file_validator.dart

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ List<Diagnostic> analyzeAnalysisOptions(
3333
VersionConstraint? sdkVersionConstraint,
3434
ResourceProvider resourceProvider,
3535
) {
36-
List<Diagnostic> errors = [];
36+
List<Diagnostic> diagnostics = [];
3737
Source initialSource = source;
3838
SourceSpan? initialIncludeSpan;
3939
AnalysisOptionsProvider optionsProvider = AnalysisOptionsProvider(
@@ -46,21 +46,21 @@ List<Diagnostic> analyzeAnalysisOptions(
4646
// functions, and should be refactored to a class maintaining state, with less
4747
// variable shadowing.
4848
void addDirectErrorOrIncludedError(
49-
List<Diagnostic> validationErrors,
49+
List<Diagnostic> validationDiagnostics,
5050
Source source, {
5151
required bool isSourcePrimary,
5252
}) {
5353
if (!isSourcePrimary) {
54-
// [source] is an included file, and we should only report errors in
54+
// [source] is an included file, and we should only report diagnostics in
5555
// [initialSource], noting that the included file has warnings.
56-
for (Diagnostic error in validationErrors) {
56+
for (Diagnostic diagnostic in validationDiagnostics) {
5757
var args = [
5858
source.fullName,
59-
error.offset.toString(),
60-
(error.offset + error.length - 1).toString(),
61-
error.message,
59+
diagnostic.offset.toString(),
60+
(diagnostic.offset + diagnostic.length - 1).toString(),
61+
diagnostic.message,
6262
];
63-
errors.add(
63+
diagnostics.add(
6464
Diagnostic.tmp(
6565
source: initialSource,
6666
offset: initialIncludeSpan!.start.offset,
@@ -71,9 +71,9 @@ List<Diagnostic> analyzeAnalysisOptions(
7171
);
7272
}
7373
} else {
74-
// [source] is the options file for [contextRoot]. Report all errors
74+
// [source] is the options file for [contextRoot]. Report all diagnostics
7575
// directly.
76-
errors.addAll(validationErrors);
76+
diagnostics.addAll(validationDiagnostics);
7777
}
7878
}
7979

@@ -123,7 +123,7 @@ List<Diagnostic> analyzeAnalysisOptions(
123123

124124
var includedSource = sourceFactory.resolveUri(source, includeUri);
125125
if (includedSource == initialSource) {
126-
errors.add(
126+
diagnostics.add(
127127
Diagnostic.tmp(
128128
source: initialSource,
129129
offset: initialIncludeSpan!.start.offset,
@@ -135,7 +135,7 @@ List<Diagnostic> analyzeAnalysisOptions(
135135
return;
136136
}
137137
if (includedSource == null || !includedSource.exists()) {
138-
errors.add(
138+
diagnostics.add(
139139
Diagnostic.tmp(
140140
source: initialSource,
141141
offset: initialIncludeSpan!.start.offset,
@@ -148,7 +148,7 @@ List<Diagnostic> analyzeAnalysisOptions(
148148
}
149149
var spanInChain = includeChain[includedSource];
150150
if (spanInChain != null) {
151-
errors.add(
151+
diagnostics.add(
152152
Diagnostic.tmp(
153153
source: initialSource,
154154
offset: initialIncludeSpan!.start.offset,
@@ -190,9 +190,9 @@ List<Diagnostic> analyzeAnalysisOptions(
190190
e.span!.end.offset.toString(),
191191
e.message,
192192
];
193-
// Report errors for included option files on the `include` directive
193+
// Report diagnostics for included option files on the `include` directive
194194
// located in the initial options file.
195-
errors.add(
195+
diagnostics.add(
196196
Diagnostic.tmp(
197197
source: initialSource,
198198
offset: initialIncludeSpan!.start.offset,
@@ -227,7 +227,7 @@ List<Diagnostic> analyzeAnalysisOptions(
227227
validate(source, options, contextRoot: contextRoot);
228228
} on OptionsFormatException catch (e) {
229229
SourceSpan span = e.span!;
230-
errors.add(
230+
diagnostics.add(
231231
Diagnostic.tmp(
232232
source: source,
233233
offset: span.start.offset,
@@ -237,7 +237,7 @@ List<Diagnostic> analyzeAnalysisOptions(
237237
),
238238
);
239239
}
240-
return errors;
240+
return diagnostics;
241241
}
242242

243243
/// Returns the name of the first legacy plugin, if one is specified in

pkg/analyzer/lib/src/dart/constant/constant_verifier.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,31 +1270,31 @@ class _ConstLiteralVerifier {
12701270
if (notPotentiallyConstants.isEmpty) return true;
12711271

12721272
for (var notConst in notPotentiallyConstants) {
1273-
DiagnosticCode errorCode;
1273+
DiagnosticCode diagnosticCode;
12741274
if (listElementType != null) {
1275-
errorCode = diag.nonConstantListElement;
1275+
diagnosticCode = diag.nonConstantListElement;
12761276
} else if (mapConfig != null) {
1277-
errorCode = diag.nonConstantMapElement;
1277+
diagnosticCode = diag.nonConstantMapElement;
12781278
for (
12791279
AstNode? parent = notConst;
12801280
parent != null;
12811281
parent = parent.parent
12821282
) {
12831283
if (parent is MapLiteralEntry) {
12841284
if (parent.key == notConst) {
1285-
errorCode = diag.nonConstantMapKey;
1285+
diagnosticCode = diag.nonConstantMapKey;
12861286
} else {
1287-
errorCode = diag.nonConstantMapValue;
1287+
diagnosticCode = diag.nonConstantMapValue;
12881288
}
12891289
break;
12901290
}
12911291
}
12921292
} else if (setConfig != null) {
1293-
errorCode = diag.nonConstantSetElement;
1293+
diagnosticCode = diag.nonConstantSetElement;
12941294
} else {
12951295
throw UnimplementedError();
12961296
}
1297-
verifier._diagnosticReporter.atNode(notConst, errorCode);
1297+
verifier._diagnosticReporter.atNode(notConst, diagnosticCode);
12981298
}
12991299

13001300
return false;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ class BinaryExpressionResolver {
146146
);
147147

148148
void reportNullComparison(SyntacticEntity start, SyntacticEntity end) {
149-
var errorCode = notEqual
149+
var diagnosticCode = notEqual
150150
? diag.unnecessaryNullComparisonAlwaysNullFalse
151151
: diag.unnecessaryNullComparisonAlwaysNullTrue;
152152
var offset = start.offset;
153153
_diagnosticReporter.atOffset(
154154
offset: offset,
155155
length: end.end - offset,
156-
diagnosticCode: errorCode,
156+
diagnosticCode: diagnosticCode,
157157
);
158158
}
159159

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,22 @@ class FunctionReferenceResolver {
9292
TypeArgumentList typeArgumentList,
9393
String? name,
9494
List<TypeParameterElement> typeParameters,
95-
DiagnosticCode errorCode,
95+
DiagnosticCode diagnosticCode,
9696
) {
9797
if (typeArgumentList.arguments.length != typeParameters.length) {
9898
if (name == null &&
99-
errorCode == diag.wrongNumberOfTypeArgumentsFunction) {
100-
errorCode = diag.wrongNumberOfTypeArgumentsAnonymousFunction;
99+
diagnosticCode == diag.wrongNumberOfTypeArgumentsFunction) {
100+
diagnosticCode = diag.wrongNumberOfTypeArgumentsAnonymousFunction;
101101
_diagnosticReporter.atNode(
102102
typeArgumentList,
103-
errorCode,
103+
diagnosticCode,
104104
arguments: [typeParameters.length, typeArgumentList.arguments.length],
105105
);
106106
} else {
107107
assert(name != null);
108108
_diagnosticReporter.atNode(
109109
typeArgumentList,
110-
errorCode,
110+
diagnosticCode,
111111
arguments: [
112112
name!,
113113
typeParameters.length,

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,27 +125,27 @@ class TypePropertyResolver {
125125
}
126126
}
127127

128-
DiagnosticCode errorCode;
128+
DiagnosticCode diagnosticCode;
129129
List<String> arguments;
130130
if (parentNode == null) {
131-
errorCode = diag.uncheckedInvocationOfNullableValue;
131+
diagnosticCode = diag.uncheckedInvocationOfNullableValue;
132132
arguments = [];
133133
} else {
134134
if (parentNode is CascadeExpression) {
135135
parentNode = parentNode.cascadeSections.first;
136136
}
137137
if (parentNode is BinaryExpression || parentNode is RelationalPattern) {
138-
errorCode = diag.uncheckedOperatorInvocationOfNullableValue;
138+
diagnosticCode = diag.uncheckedOperatorInvocationOfNullableValue;
139139
arguments = [name];
140140
} else if (parentNode is MethodInvocation ||
141141
parentNode is MethodReferenceExpression) {
142-
errorCode = diag.uncheckedMethodInvocationOfNullableValue;
142+
diagnosticCode = diag.uncheckedMethodInvocationOfNullableValue;
143143
arguments = [name];
144144
} else if (parentNode is FunctionExpressionInvocation) {
145-
errorCode = diag.uncheckedInvocationOfNullableValue;
145+
diagnosticCode = diag.uncheckedInvocationOfNullableValue;
146146
arguments = [];
147147
} else {
148-
errorCode = diag.uncheckedPropertyAccessOfNullableValue;
148+
diagnosticCode = diag.uncheckedPropertyAccessOfNullableValue;
149149
arguments = [name];
150150
}
151151
}
@@ -169,7 +169,7 @@ class TypePropertyResolver {
169169
}
170170
}
171171
_resolver.nullableDereferenceVerifier.report(
172-
errorCode,
172+
diagnosticCode,
173173
propertyErrorEntity,
174174
receiverType,
175175
arguments: arguments,

pkg/analyzer/lib/src/dart/scanner/scanner.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class Scanner {
6464

6565
/// Initialize a newly created scanner to scan characters from the given
6666
/// [source]. The given character [reader] will be used to read the characters
67-
/// in the source. The given [_diagnosticListener] will be informed of any errors
68-
/// that are found.
67+
/// in the source. The given [_diagnosticListener] will be informed of any
68+
/// errors that are found.
6969
factory Scanner(
7070
Source source,
7171
CharacterReader reader,
@@ -128,7 +128,7 @@ class Scanner {
128128
}
129129

130130
void reportError(
131-
DiagnosticCode errorCode,
131+
DiagnosticCode diagnosticCode,
132132
int offset,
133133
List<Object?>? arguments,
134134
) {
@@ -137,7 +137,7 @@ class Scanner {
137137
source: source,
138138
offset: offset,
139139
length: 1,
140-
diagnosticCode: errorCode,
140+
diagnosticCode: diagnosticCode,
141141
arguments: arguments ?? const [],
142142
),
143143
);

pkg/analyzer/lib/src/dart/scanner/translate_error_token.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ void translateErrorToken(ErrorToken token, ReportError reportError) {
1616
int charOffset = token.charOffset;
1717
// TODO(paulberry): why is endOffset sometimes null?
1818
int endOffset = token.endOffset ?? charOffset;
19-
void makeError(DiagnosticCode errorCode, List<Object>? arguments) {
19+
void makeError(DiagnosticCode code, List<Object>? arguments) {
2020
if (_isAtEnd(token, charOffset)) {
2121
// Analyzer never generates an error message past the end of the input,
2222
// since such an error would not be visible in an editor.
2323
// TODO(paulberry): would it make sense to replicate this behavior
2424
// in cfe, or move it elsewhere in analyzer?
2525
charOffset--;
2626
}
27-
reportError(errorCode, charOffset, arguments);
27+
reportError(code, charOffset, arguments);
2828
}
2929

3030
Code errorCode = token.errorCode;
@@ -111,11 +111,11 @@ bool _isAtEnd(Token token, int charOffset) {
111111
}
112112

113113
/// Used to report a scan error at the given offset.
114-
/// The [errorCode] is the error code indicating the nature of the error.
114+
/// The [diagnosticCode] is the error code indicating the nature of the error.
115115
/// The [arguments] are any arguments needed to complete the error message.
116116
typedef ReportError =
117117
void Function(
118-
DiagnosticCode errorCode,
118+
DiagnosticCode diagnosticCode,
119119
int offset,
120120
List<Object>? arguments,
121121
);

0 commit comments

Comments
 (0)