diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index ac0ebdd0b1..98cfd121c0 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -3954,6 +3954,11 @@ static NodeBase* parseSubscriptDecl(Parser* parser, void* /*userData*/) decl->returnType.exp = parser->astBuilder->create(); } + auto funcScope = parser->currentScope; + parser->PopScope(); + maybeParseGenericConstraints(parser, genericParent); + parser->PushScope(funcScope); + parseStorageDeclBody(parser, decl); parser->PopScope(); diff --git a/tests/language-feature/generics/generic-subscript.slang b/tests/language-feature/generics/generic-subscript.slang new file mode 100644 index 0000000000..87eec3045c --- /dev/null +++ b/tests/language-feature/generics/generic-subscript.slang @@ -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 output; + +struct Tx +{ + float x; + __subscript(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]; +} \ No newline at end of file