mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 12:48:10 +00:00
[test_runner] Fix RangeError when parsing static errors
Previously it tested if it was at the end of file (defined as _currentLine >= _lines.length), if it was not it would try to read the _next_ line (_peek(1)), meaning that if _currentLine = _lines.length - 1 it would _peek(1) and try to read _lines[lines.length] and crash with a range error. This CL fixes it by actually checking if it can safely peek the amount it wants to. Change-Id: I2e66c539e823f0b39bd0da39e2b2277a9e6c9501 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150624 Commit-Queue: Bob Nystrom <rnystrom@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
parent
5900da5418
commit
214cdbdc81
|
@ -456,7 +456,7 @@ class _ErrorExpectationParser {
|
|||
_ErrorExpectationParser(String source) : _lines = source.split("\n");
|
||||
|
||||
List<StaticError> _parse() {
|
||||
while (!_isAtEnd) {
|
||||
while (_canPeek(0)) {
|
||||
var sourceLine = _peek(0);
|
||||
|
||||
var match = _caretLocationRegExp.firstMatch(sourceLine);
|
||||
|
@ -504,7 +504,7 @@ class _ErrorExpectationParser {
|
|||
|
||||
var startLine = _currentLine;
|
||||
|
||||
while (!_isAtEnd) {
|
||||
while (_canPeek(1)) {
|
||||
var match = _errorMessageRegExp.firstMatch(_peek(1));
|
||||
if (match == null) break;
|
||||
|
||||
|
@ -516,7 +516,7 @@ class _ErrorExpectationParser {
|
|||
_advance();
|
||||
|
||||
// Consume as many additional error message lines as we find.
|
||||
while (!_isAtEnd) {
|
||||
while (_canPeek(1)) {
|
||||
var nextLine = _peek(1);
|
||||
|
||||
// A location line shouldn't be treated as part of the message.
|
||||
|
@ -585,7 +585,7 @@ class _ErrorExpectationParser {
|
|||
markerEndLine: _currentLine));
|
||||
}
|
||||
|
||||
bool get _isAtEnd => _currentLine >= _lines.length;
|
||||
bool _canPeek(int offset) => _currentLine + offset < _lines.length;
|
||||
|
||||
void _advance() {
|
||||
_currentLine++;
|
||||
|
|
|
@ -287,6 +287,17 @@ someBadCode();
|
|||
/\/ [cfe] Wrong 1.
|
||||
""");
|
||||
|
||||
// Don't crash with RangeError.
|
||||
expectUpdate("""
|
||||
x
|
||||
// [error line 1, column 1, length 0]
|
||||
// [cfe] Whatever""", errors: [
|
||||
makeError(line: 1, column: 1, length: 0, cfeError: "Foo"),
|
||||
], expected: """
|
||||
x
|
||||
// [error line 1, column 1, length 0]
|
||||
// [cfe] Foo""");
|
||||
|
||||
regression();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue