diff options
| author | Yong He <yonghe@outlook.com> | 2024-02-11 01:05:37 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-11 01:05:37 -0800 |
| commit | 4f7d1f44a4b2a5eab2e2dec1edf3a156da78aae3 (patch) | |
| tree | 983b505f39a8e884e8af46ba4b7c1d3e80d708aa /tests/language-feature/generics | |
| parent | 03cddba97e821c013023d51fb7d3d61a130a2a9f (diff) | |
Fix type checking around generic array types. (#3568)
Diffstat (limited to 'tests/language-feature/generics')
| -rw-r--r-- | tests/language-feature/generics/generic-interface-2.slang | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/language-feature/generics/generic-interface-2.slang b/tests/language-feature/generics/generic-interface-2.slang new file mode 100644 index 000000000..9a44f679c --- /dev/null +++ b/tests/language-feature/generics/generic-interface-2.slang @@ -0,0 +1,42 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -output-using-type + +interface IFoo<let n: uint> +{ + static int sum(int arr[n]); +} + +struct MyType<let n:uint> : IFoo<n> +{ + static int sum(int arr[n]) + { + int rs = 0; + for (int i = 0; i < n; i++) + rs += arr[i]; + return rs; + } +} + +int test<let n:uint>(IFoo<n> foo) +{ + int arr[n]; + for (int i =0; i < n; i++) + arr[i] = i; + return foo.sum(arr); +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + MyType<3> t; + test(t); + // CHECK: 3 + outputBuffer[0] = test(t); + + int arr[3] = {1,2,3}; + // CHECK: 3 + outputBuffer[1] = MyType<3>.sum(arr); +} |
