diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 172e3130f2..4dc962ce6c 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(stmt->initialStatement) || as(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); diff --git a/tests/language-feature/modules/typealias/lib.slang b/tests/language-feature/modules/typealias/lib.slang new file mode 100644 index 0000000000..72a31ef09f --- /dev/null +++ b/tests/language-feature/modules/typealias/lib.slang @@ -0,0 +1,3 @@ +//TEST_IGNORE_FILE: + +typealias i32 = int32_t; diff --git a/tests/language-feature/modules/typealias/main.slang b/tests/language-feature/modules/typealias/main.slang new file mode 100644 index 0000000000..965aec6425 --- /dev/null +++ b/tests/language-feature/modules/typealias/main.slang @@ -0,0 +1,24 @@ +//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -output-using-type + +// Regression test for bug https://github.com/shader-slang/slang/issues/5808 + +// Using a type defined from a different module +// in a for loop should work. + +import lib; + +//TEST_INPUT:set output = out ubuffer(data=[0 0 0 0], stride=4) +RWStructuredBuffer output; + +[numthreads(1,1,1)] +void computeMain() +{ + // CHECK: 0 + // CHECK: 1 + // CHECK: 2 + // CHECK: 3 + for (i32 i = 0; i < 4; i++) + { + output[i] = i; + } +} \ No newline at end of file