Skip to content

Commit

Permalink
Merge branch 'master' into half-coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
expipiplus1 authored Dec 10, 2024
2 parents 7e24e25 + 945d8dd commit 2408c18
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
21 changes: 12 additions & 9 deletions source/slang/slang-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions tests/language-feature/modules/typealias/lib.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//TEST_IGNORE_FILE:

typealias i32 = int32_t;
24 changes: 24 additions & 0 deletions tests/language-feature/modules/typealias/main.slang
Original file line number Diff line number Diff line change
@@ -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<i32> 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;
}
}

0 comments on commit 2408c18

Please sign in to comment.