Skip to content

Commit

Permalink
Fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
csyonghe committed Jan 17, 2025
1 parent 603a86c commit 2b07600
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions source/slang/slang-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3954,6 +3954,11 @@ static NodeBase* parseSubscriptDecl(Parser* parser, void* /*userData*/)
decl->returnType.exp = parser->astBuilder->create<IncompleteExpr>();
}

auto funcScope = parser->currentScope;
parser->PopScope();
maybeParseGenericConstraints(parser, genericParent);
parser->PushScope(funcScope);

parseStorageDeclBody(parser, decl);

parser->PopScope();
Expand Down
24 changes: 24 additions & 0 deletions tests/language-feature/generics/generic-subscript.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -output-using-type

//TEST_INPUT: set output = out ubuffer(data=[0 0 0 0], stride=4)
RWStructuredBuffer<float> output;

struct Tx
{
float x;
__subscript<I>(I index) -> float
where I:IInteger
{
get { return x + index.toInt(); }
set { x = newValue;}
}
}

[numthreads(1,1,1)]
void computeMain()
{
Tx obj;
obj[0] = 3.0;
// CHECK: 5.0
output[0] = obj[2];
}

0 comments on commit 2b07600

Please sign in to comment.