summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/compute/mutating-methods.slang51
-rw-r--r--tests/compute/mutating-methods.slang.expected.txt4
-rw-r--r--tests/diagnostics/setter-method.slang.expected4
3 files changed, 57 insertions, 2 deletions
diff --git a/tests/compute/mutating-methods.slang b/tests/compute/mutating-methods.slang
new file mode 100644
index 000000000..736d4f7e0
--- /dev/null
+++ b/tests/compute/mutating-methods.slang
@@ -0,0 +1,51 @@
+// mutating-methods.slang
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
+
+interface IAccumulator
+{
+ [mutating] void accumulate(int v);
+}
+
+struct Accumulator : IAccumulator
+{
+ int state;
+
+ [mutating] void accumulate(int v)
+ {
+ state += v;
+ }
+
+ [mutating] void accumulateMore(int v)
+ {
+ this.state += v;
+ }
+}
+
+void doStuff<A : IAccumulator>(inout A a)
+{
+ a.accumulate(16);
+}
+
+int test(int x)
+{
+ Accumulator a;
+ a.state = 0;
+
+ a.accumulate(x);
+ a.accumulateMore(x);
+ doStuff(a);
+
+ return a.state;
+}
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int tid = dispatchThreadID.x;
+ outputBuffer[tid] = test(tid);
+}
diff --git a/tests/compute/mutating-methods.slang.expected.txt b/tests/compute/mutating-methods.slang.expected.txt
new file mode 100644
index 000000000..128492da7
--- /dev/null
+++ b/tests/compute/mutating-methods.slang.expected.txt
@@ -0,0 +1,4 @@
+10
+12
+14
+16
diff --git a/tests/diagnostics/setter-method.slang.expected b/tests/diagnostics/setter-method.slang.expected
index 237c499ee..0c2b5a2c9 100644
--- a/tests/diagnostics/setter-method.slang.expected
+++ b/tests/diagnostics/setter-method.slang.expected
@@ -1,9 +1,9 @@
result code = -1
standard error = {
tests/diagnostics/setter-method.slang(16): error 30011: left of '=' is not an l-value.
-tests/diagnostics/setter-method.slang(16): note 30049: a 'this' parameter is currently immutable in Slang
+tests/diagnostics/setter-method.slang(16): note 30049: a 'this' parameter is an immutable parameter by default in Slang; apply the `[mutating]` attribute to the function declaration to opt in to a mutable `this`
tests/diagnostics/setter-method.slang(21): error 30011: left of '=' is not an l-value.
-tests/diagnostics/setter-method.slang(21): note 30049: a 'this' parameter is currently immutable in Slang
+tests/diagnostics/setter-method.slang(21): note 30049: a 'this' parameter is an immutable parameter by default in Slang; apply the `[mutating]` attribute to the function declaration to opt in to a mutable `this`
}
standard output = {
}