Skip to content

Commit

Permalink
fix conditional expression parsing with NNBD enabled
Browse files Browse the repository at this point in the history
Fix dart-lang/sdk#38113

Change-Id: I06ebb5ee6260dfa97969a7d11b8c66c48d2ae766
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/116054
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
danrubel authored and commit-bot@chromium.org committed Sep 9, 2019
1 parent fb446e5 commit 618b56d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions pkg/analyzer/test/generated/parser_fasta_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2611,6 +2611,17 @@ class NNBDParserTest_Fasta extends FastaParserTestCase {
parseCompilationUnit('main() { for(int? x in [7, null]) { } }');
}

test_fuzz_38113() async {
// https://github.com/dart-lang/sdk/issues/38113
await parseCompilationUnit(r'+t{{r?this}}', errors: [
expectedError(ParserErrorCode.EXPECTED_EXECUTABLE, 0, 1),
expectedError(ParserErrorCode.MISSING_FUNCTION_PARAMETERS, 1, 1),
expectedError(ParserErrorCode.MISSING_IDENTIFIER, 6, 4),
expectedError(ParserErrorCode.EXPECTED_TOKEN, 10, 1),
expectedError(ParserErrorCode.EXPECTED_TOKEN, 10, 1),
]);
}

void test_gft_nullable() {
parseCompilationUnit('main() { C? Function() x = 7; }');
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/front_end/lib/src/fasta/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5438,7 +5438,12 @@ class Parser {
typeInfo.isNullable &&
typeInfo.couldBeExpression) {
assert(optional('?', token));
assert(next.isIdentifier);
assert(next.isKeywordOrIdentifier);
if (!next.isIdentifier) {
reportRecoverableError(
next, fasta.templateExpectedIdentifier.withArguments(next));
next = rewriter.insertSyntheticIdentifier(next);
}
Token afterIdentifier = next.next;
//
// found <typeref> `?` <identifier>
Expand Down

0 comments on commit 618b56d

Please sign in to comment.