diff options
| author | Yong He <yonghe@outlook.com> | 2024-12-10 03:47:16 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-10 19:47:16 +0800 |
| commit | 945d8dd3c4cea58f3d9f36e8fa123137f64e180e (patch) | |
| tree | 686af1024736a5e553c57fc49f4310b0f501571c /source/slang/slang-parser.cpp | |
| parent | ebfbe5886f273e0492321c5ff0c9c2671583a648 (diff) | |
Fix parsing logic of for loops' initial statement. (#5813)
Diffstat (limited to 'source/slang/slang-parser.cpp')
| -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); |
