Skip to content

Commit d63f5e2

Browse files
authored
Allow a enum case to reference a previously defined value. (shader-slang#4768)
1 parent 69dd7f4 commit d63f5e2

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

source/slang/slang-check-decl.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,9 @@ namespace Slang
788788
if(as<ConstructorDecl>(decl))
789789
return true;
790790

791+
if (as<EnumCaseDecl>(decl))
792+
return true;
793+
791794
// Things nested inside functions may have dependencies
792795
// on values from the enclosing scope, but this needs to
793796
// be dealt with via "capture" so they are also effectively

source/slang/slang-parser.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -4945,6 +4945,7 @@ namespace Slang
49454945
parseOptionalInheritanceClause(parser, decl);
49464946
parser->ReadToken(TokenType::LBrace);
49474947
Token closingToken;
4948+
parser->pushScopeAndSetParent(decl);
49484949
while (!AdvanceIfMatch(parser, MatchedTokenType::CurlyBraces, &closingToken))
49494950
{
49504951
EnumCaseDecl* caseDecl = parseEnumCaseDecl(parser);
@@ -4955,6 +4956,7 @@ namespace Slang
49554956

49564957
parser->ReadToken(TokenType::Comma);
49574958
}
4959+
parser->PopScope();
49584960
decl->closingSourceLoc = closingToken.loc;
49594961
return decl;
49604962
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj
2+
3+
// Test that a enum case can reference a previously defined case.
4+
5+
enum Check { V = 1, X = V+2 };
6+
7+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
8+
RWStructuredBuffer<int> outputBuffer;
9+
10+
[numthreads(1, 1, 1)]
11+
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
12+
{
13+
// CHECK: 3
14+
outputBuffer[0] = Check.X;
15+
}

0 commit comments

Comments
 (0)