diff options
| author | Mukund Keshava <mkeshava@nvidia.com> | 2025-05-27 20:24:15 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-27 14:54:15 +0000 |
| commit | 9ef7072397457e8cdb8a63a1a6953d01f46b2904 (patch) | |
| tree | e0745658201dd89f36d033f96c8a27798f462bbd /tests/diagnostics | |
| parent | f570e109c4039e15526af38e17f350c115327489 (diff) | |
Add check for subscript operator return type (#7244)
Fixes #6987
Diffstat (limited to 'tests/diagnostics')
| -rw-r--r-- | tests/diagnostics/subscript-missing-return-type.slang | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/diagnostics/subscript-missing-return-type.slang b/tests/diagnostics/subscript-missing-return-type.slang new file mode 100644 index 000000000..23c2cda5e --- /dev/null +++ b/tests/diagnostics/subscript-missing-return-type.slang @@ -0,0 +1,32 @@ +// Test that __subscript without return type produces proper error message + +//TEST:SIMPLE(filecheck=CHECK): -target spirv + +struct MyType +{ + int val[12]; + + // CHECK: ([[# @LINE+1]]): error 30901: __subscript declaration must have a return type specified after '->' + __subscript(int x, int y) + { + get { return val[x*3 + y]; } + } +} + +// This should compile fine - subscript with return type +struct MyType2 +{ + int val[12]; + __subscript(int x, int y) -> int + { + get { return val[x*3 + y]; } + } +} + +[shader("compute")] +[numthreads(1,1,1)] +void computeMain() +{ + MyType2 obj; + int v = obj[1, 2]; +}
\ No newline at end of file |
