Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1385)

Unified Diff: runtime/vm/parser.cc

Issue 2946173002: VM: Allow trailing comma in assert statements. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/language/assert_trailing_comma_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc
index 6f639387c126ac232945dfea4ccc80cac1915855..adf26884e2268e8d12335169cc20e6a8051c7c91 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -9697,7 +9697,13 @@ AstNode* Parser::ParseAssertStatement(bool is_const) {
SkipExpr();
if (CurrentToken() == Token::kCOMMA) {
ConsumeToken();
- SkipExpr();
+ if (CurrentToken() != Token::kRPAREN) {
+ SkipExpr();
+ if (CurrentToken() == Token::kCOMMA) {
+ // Allow trailing comma.
+ ConsumeToken();
+ }
+ }
}
ExpectToken(Token::kRPAREN);
return NULL;
@@ -9714,12 +9720,18 @@ AstNode* Parser::ParseAssertStatement(bool is_const) {
TokenPosition message_pos = TokenPosition::kNoSource;
if (CurrentToken() == Token::kCOMMA) {
ConsumeToken();
- message_pos = TokenPos();
- message = ParseExpr(kAllowConst, kConsumeCascades);
- if (is_const && !message->IsPotentiallyConst()) {
- ReportError(
- message_pos,
- "initializer assert expression must be compile time constant.");
+ if (CurrentToken() != Token::kRPAREN) {
+ message_pos = TokenPos();
+ message = ParseExpr(kAllowConst, kConsumeCascades);
+ if (is_const && !message->IsPotentiallyConst()) {
+ ReportError(
+ message_pos,
+ "initializer assert expression must be compile time constant.");
+ }
+ if (CurrentToken() == Token::kCOMMA) {
+ // Allow trailing comma.
+ ConsumeToken();
+ }
}
}
ExpectToken(Token::kRPAREN);
« no previous file with comments | « no previous file | tests/language/assert_trailing_comma_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698