diff options
| author | Yong He <yonghe@outlook.com> | 2024-09-27 17:11:07 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-27 17:11:07 -0700 |
| commit | afb1405bf7974d714cee10fcce0c61fe28cd075d (patch) | |
| tree | f4016719071aefc7f8d353defd729c6a542612e9 /tests/bugs/gh-4971.slang | |
| parent | f667593e77e18521b7f3bf4f339c2549b5e5eb1b (diff) | |
Fix l-value computation for subscript call. (#5177)
Diffstat (limited to 'tests/bugs/gh-4971.slang')
| -rw-r--r-- | tests/bugs/gh-4971.slang | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/bugs/gh-4971.slang b/tests/bugs/gh-4971.slang new file mode 100644 index 000000000..948e43385 --- /dev/null +++ b/tests/bugs/gh-4971.slang @@ -0,0 +1,25 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-d3d11 -output-using-type + +struct Test { + RWStructuredBuffer<int> val; + __subscript(int x, int y)->int + { + get { return val[x * 3 + y]; } + [nonmutating] set { val[x * 3 + y] = newValue; } + } +} +Test test; + +//TEST_INPUT: set test = {out ubuffer(data=[0 0 0 0 0 0 0 0 0], stride=4)}; + +[numthreads(1, 1, 1)] +void computeMain() +{ + // test[0,0] should be a valid l-value here because although `test` is + // a read-only parameter, the `set` accessor is marked as `nonmutating`, + // which means that it can be called even when `test` is not mutable. + + // CHECK: 1 + test[0,0] = 1; +}
\ No newline at end of file |
