diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-parser.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 172e3130f..4dc962ce6 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -5953,22 +5953,25 @@ ForStmt* Parser::ParseForStatement() FillPosition(stmt); ReadToken("for"); ReadToken(TokenType::LParent); - auto modifiers = ParseModifiers(this); - if (peekTypeName(this) || !modifiers.isEmpty()) - { - stmt->initialStatement = parseVarDeclrStatement(modifiers); - } - else + if (!LookAheadToken(TokenType::Semicolon)) { - if (!LookAheadToken(TokenType::Semicolon)) + stmt->initialStatement = ParseStatement(); + if (as<DeclStmt>(stmt->initialStatement) || as<ExpressionStmt>(stmt->initialStatement)) { - stmt->initialStatement = ParseExpressionStatement(); + // These are the only allowed form of initial statements of a for loop. } else { - ReadToken(TokenType::Semicolon); + sink->diagnose( + stmt->initialStatement->loc, + Diagnostics::unexpectedTokenExpectedTokenType, + "expression"); } } + else + { + ReadToken(TokenType::Semicolon); + } if (!LookAheadToken(TokenType::Semicolon)) stmt->predicateExpression = ParseExpression(); ReadToken(TokenType::Semicolon); |
