Skip to content

Commit 1f10afc

Browse files
munificentcommit-bot@chromium.org
authored andcommitted
Don't use explicit error locations for CFE-only errors.
The CFE currently does not report the length in an error location, just the starting position. When the static error update tool inserts an error marker for an error reported only by the CFE, it doesn't know what length to use. It used to deal with this by always writing an explicit error location like: // [error line 1, column 9] Those are kind of ugly and brittle, though. This changes it to treat the error as implicitly having length 1. This way, it can just output: // ^ When validating an error expectation against a report CFE error, the length is ignored anyway (since the CFE doesn't report it). In order to ensure that the parsed output of the tool matches the reported data that produced it, the parser also ignores the length when parsing an error expectation for a CFE-only error with length one. Fix #37991. Change-Id: I20e109142546b7e82a5f796a1a40613b90dc89bd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114745 Reviewed-by: Leaf Petersen <[email protected]> Commit-Queue: Bob Nystrom <[email protected]>
1 parent 5148afa commit 1f10afc

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

pkg/test_runner/lib/src/test_file.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,14 @@ class ErrorExpectationParser {
921921
"error.");
922922
}
923923

924+
// Hack: If the error is CFE-only and the length is one, treat it as no
925+
// length. The CFE does not output length information, and when the update
926+
// tool writes a CFE-only error, it implicitly uses a length of one. Thus,
927+
// when we parse back in a length one CFE error, we ignore the length so
928+
// that the error round-trips correctly.
929+
// TODO(rnystrom): Stop doing this when the CFE reports error lengths.
930+
if (code == null && length == 1) length = null;
931+
924932
_errors.add(StaticError(
925933
line: line,
926934
column: column,

pkg/test_runner/lib/src/update_errors.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,15 @@ String updateErrorExpectations(String source, List<StaticError> errors,
9696

9797
var comment = (" " * indent) + "//";
9898

99-
// If the error can't fit in a line comment or doesn't have a length, use
100-
// an explicit location.
101-
if (error.length == null) {
102-
result.add("$comment [error line $codeLine, column ${error.column}]");
103-
} else if (error.column <= 2) {
104-
result.add("$comment [error line $codeLine, column ${error.column}, "
105-
"length ${error.length}]");
99+
// If the error can't fit in a line comment, use an explicit location.
100+
if (error.column <= 2) {
101+
if (error.length == null) {
102+
result.add("$comment [error line $codeLine, column "
103+
"${error.column}]");
104+
} else {
105+
result.add("$comment [error line $codeLine, column "
106+
"${error.column}, length ${error.length}]");
107+
}
106108
} else {
107109
var spacing = " " * (error.column - 1 - 2 - indent);
108110
// A CFE-only error may not have a length, so treat it as length 1.

pkg/test_runner/test/test_file_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,22 @@ int i = "s";
457457
/\/ ^^^
458458
/\/ [analyzer] Not error code.
459459
""");
460+
461+
// A CFE-only error with length one is treated as having no length.
462+
expectParseErrorExpectations("""
463+
int i = "s";
464+
/\/ ^
465+
/\/ [cfe] Message.
466+
467+
int j = "s";
468+
/\/ ^
469+
/\/ [analyzer] Error.BAD
470+
/\/ [cfe] Message.
471+
""", [
472+
StaticError(line: 1, column: 9, length: null, message: "Message."),
473+
StaticError(
474+
line: 5, column: 9, length: 1, code: "Error.BAD", message: "Message."),
475+
]);
460476
}
461477

462478
void testName() {

pkg/test_runner/test/update_errors_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,12 @@ int j =
192192
/\/ [cfe] Error.
193193
""");
194194

195-
// Uses an explicit error location if there's no length.
195+
// Uses length one if there's no length.
196196
expectUpdate("""
197197
int i = "bad";
198198
""", errors: [StaticError(line: 1, column: 9, message: "Error.")], expected: """
199199
int i = "bad";
200-
/\/ [error line 1, column 9]
200+
/\/ ^
201201
/\/ [cfe] Error.
202202
""");
203203

@@ -322,7 +322,7 @@ class A {
322322
yy(4);
323323
/\/ ^^^^^^^^^^^^^^
324324
/\/ [analyzer] unspecified
325-
/\/ [error line 12, column 7]
325+
/\/ ^
326326
/\/ [cfe] The method 'call' isn't defined for the class 'int'.
327327
328328
}

0 commit comments

Comments
 (0)