summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2019-02-05 19:41:33 -0800
committerGitHub <noreply@github.com>2019-02-05 19:41:33 -0800
commit2d1291ae4f3de66e2d958b148d0811cbf2ee9c60 (patch)
treea81b861c6cbd345e323a1f5ee3bc4eec61646b96 /tests
parent3d62beab61490ce3e7ed60b48fd6a11c8eeb44ad (diff)
parentc6870dcbf6f720bfbfe7e38f7d9625d69bedde3d (diff)
Merge pull request #829 from tfoleyNV/fix-nested-type-conformances
Fix checking of interface conformances for nested types
Diffstat (limited to 'tests')
-rw-r--r--tests/compute/assoctype-nested.slang61
-rw-r--r--tests/compute/assoctype-nested.slang.expected.txt4
2 files changed, 65 insertions, 0 deletions
diff --git a/tests/compute/assoctype-nested.slang b/tests/compute/assoctype-nested.slang
new file mode 100644
index 000000000..b3d96306b
--- /dev/null
+++ b/tests/compute/assoctype-nested.slang
@@ -0,0 +1,61 @@
+// assoctype-nested.slang
+
+// Confirm that an associated type can be declared nested in its parent.
+
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
+
+interface IRandomGenerator
+{
+ [mutating] int generateVal();
+}
+
+interface IRandomStrategy
+{
+ associatedtype Generator : IRandomGenerator;
+ Generator makeGenerator(int seed);
+}
+
+int helper<T:IRandomStrategy>(T strategy, int seed)
+{
+ var generator = strategy.makeGenerator(seed);
+ let val = generator.generateVal();
+ return val;
+}
+
+struct CounterStrategy : IRandomStrategy
+{
+ struct Generator : IRandomGenerator
+ {
+ int state;
+ [mutating] int generateVal()
+ {
+ return state++;
+ }
+ }
+
+ Generator makeGenerator(int seed)
+ {
+ Generator generator = { seed };
+ return generator;
+ }
+}
+
+int test(int val)
+{
+ CounterStrategy strategy;
+ return helper(strategy, val);
+}
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
+RWStructuredBuffer<int> gOutputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+ int inputVal = tid;
+ int outputVal = test(inputVal);
+ gOutputBuffer[tid] = outputVal;
+} \ No newline at end of file
diff --git a/tests/compute/assoctype-nested.slang.expected.txt b/tests/compute/assoctype-nested.slang.expected.txt
new file mode 100644
index 000000000..bc856dafa
--- /dev/null
+++ b/tests/compute/assoctype-nested.slang.expected.txt
@@ -0,0 +1,4 @@
+0
+1
+2
+3