Skip to content

Commit 9c14862

Browse files
Dan Rubelcommit-bot@chromium.org
authored andcommitted
prepend missing hex digits error token
This prepends (rather than append) another error token to the token stream similar to https://dart-review.googlesource.com/c/sdk/+/110100 In addition, this addresses a comment in https://dart-review.googlesource.com/c/sdk/+/110140 Change-Id: I27c739b0ee3213cdbce92c3ff18c31fde862251c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110141 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
1 parent 62674b9 commit 9c14862

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

pkg/analyzer/test/generated/parser_fasta_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,17 @@ main() { // missing async
10621062
]);
10631063
}
10641064

1065+
void test_constructor_this_cascade_synthetic() {
1066+
// https://github.com/dart-lang/sdk/issues/37110
1067+
parseCompilationUnit('class B extends A { B(): this.. {} }', errors: [
1068+
expectedError(ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER, 25, 4),
1069+
expectedError(ParserErrorCode.EXPECTED_TOKEN, 29, 2),
1070+
expectedError(ParserErrorCode.MISSING_IDENTIFIER, 32, 1),
1071+
expectedError(ParserErrorCode.MISSING_FUNCTION_BODY, 33, 1),
1072+
expectedError(ParserErrorCode.EXPECTED_EXECUTABLE, 35, 1),
1073+
]);
1074+
}
1075+
10651076
void test_constructor_this_field() {
10661077
// https://github.com/dart-lang/sdk/issues/36262
10671078
// https://github.com/dart-lang/sdk/issues/31198

pkg/front_end/lib/src/fasta/scanner/abstract_scanner.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import 'error_token.dart'
2626

2727
import 'keyword_state.dart' show KeywordState;
2828

29-
import 'token.dart' show CommentToken, DartDocToken, LanguageVersionToken;
29+
import 'token.dart'
30+
show CommentToken, DartDocToken, LanguageVersionToken, SyntheticStringToken;
3031

3132
import 'token_constants.dart';
3233

@@ -247,6 +248,9 @@ abstract class AbstractScanner implements Scanner {
247248
/// Append [token] to the token stream.
248249
void appendErrorToken(ErrorToken token);
249250

251+
/// Prepend [token] to the token stream.
252+
void prependErrorToken(ErrorToken token);
253+
250254
/**
251255
* Returns a new comment from the scan offset [start] to the current
252256
* [scanOffset] plus the [extraOffset]. For example, if the current
@@ -790,7 +794,11 @@ abstract class AbstractScanner implements Scanner {
790794
hasDigits = true;
791795
} else {
792796
if (!hasDigits) {
793-
unterminated(messageExpectedHexDigit, shouldAdvance: false);
797+
prependErrorToken(new UnterminatedToken(
798+
messageExpectedHexDigit, start, stringOffset));
799+
// Recovery
800+
// TODO(danrubel): append actual characters not "0"
801+
appendToken(SyntheticStringToken(TokenType.INT, "0", tokenStart));
794802
return next;
795803
}
796804
appendSubstringToken(TokenType.HEXADECIMAL, start, true);

pkg/front_end/lib/src/fasta/scanner/array_based_scanner.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ abstract class ArrayBasedScanner extends AbstractScanner {
260260
appendToken(token);
261261
}
262262

263+
@override
263264
void prependErrorToken(ErrorToken token) {
264265
hasErrors = true;
265266
if (_errorTail == tail) {

pkg/front_end/lib/src/fasta/scanner/recover.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ Token scannerRecovery(List<int> bytes, Token tokens, List<int> lineStarts) {
135135
}
136136

137137
recoverHexDigit() {
138-
return synthesizeToken(errorTail.charOffset, "0", TokenType.INT)
139-
..setNext(errorTail.next);
138+
throw "Internal error: Hex digit error token should have been prepended";
140139
}
141140

142141
recoverStringInterpolation() {
@@ -156,7 +155,9 @@ Token scannerRecovery(List<int> bytes, Token tokens, List<int> lineStarts) {
156155

157156
// All unmatched error tokens should have been prepended
158157
Token current = tokens;
159-
while (current is ErrorToken && current.errorCode == codeUnmatchedToken) {
158+
while (current is ErrorToken &&
159+
(current.errorCode == codeUnmatchedToken ||
160+
current.errorCode == codeExpectedHexDigit)) {
160161
if (errorTail == null) {
161162
error = current;
162163
}

pkg/front_end/test/scanner_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ abstract class ScannerTestBase {
303303
}
304304

305305
void test_hexadecimal_missingDigit() {
306-
_assertError(ScannerErrorCode.MISSING_HEX_DIGIT, 1, "0x");
306+
_assertError(ScannerErrorCode.MISSING_HEX_DIGIT, 5, "a = 0x");
307307
}
308308

309309
void test_identifier() {

0 commit comments

Comments
 (0)