diff options
Diffstat (limited to 'tests/diagnostics')
4 files changed, 82 insertions, 0 deletions
diff --git a/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang b/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang new file mode 100644 index 000000000..2dbe45ccb --- /dev/null +++ b/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang @@ -0,0 +1,42 @@ +// mutating-impl-of-non-mutating-req.slang + +//DIAGNOSTIC_TEST:SIMPLE:-target hlsl -entry main + +interface IThing +{ + int processValue(int inValue); +} + +struct Counter : IThing +{ + int state; + + [mutating] int processValue(int inValue) + { + int result = state; + state += inValue; + return state; + } +} + +int helper<T : IThing>(T thing, int value) +{ + return thing.processValue(value); +} + +int test(int value) +{ + Counter counter = { value }; + return helper(counter, value); +} + +cbuffer C +{ + int gValue; +} + +[shader("fragment")] +int main() : SV_Target +{ + return test(gValue); +}
\ No newline at end of file diff --git a/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang.expected b/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang.expected new file mode 100644 index 000000000..922a6c826 --- /dev/null +++ b/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang.expected @@ -0,0 +1,6 @@ +result code = -1 +standard error = { +tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang(10): error 38100: type 'Counter' does not provide required interface member 'processValue' +} +standard output = { +} diff --git a/tests/diagnostics/methods/mutating-method-on-rvalue.slang b/tests/diagnostics/methods/mutating-method-on-rvalue.slang new file mode 100644 index 000000000..ab51244aa --- /dev/null +++ b/tests/diagnostics/methods/mutating-method-on-rvalue.slang @@ -0,0 +1,26 @@ +// mutating-method-on-rvalue.slang + +//DIAGNOSTIC_TEST:SIMPLE:-target hlsl -entry main + +struct Counter +{ + int count; + + [mutating] void increment() { count++; } + + void bad() + { + increment(); + } +} + +cbuffer C +{ + Counter gCounter; +} + +[shader("compute")] +void main() +{ + gCounter.increment(); +}
\ No newline at end of file diff --git a/tests/diagnostics/methods/mutating-method-on-rvalue.slang.expected b/tests/diagnostics/methods/mutating-method-on-rvalue.slang.expected new file mode 100644 index 000000000..878882bd3 --- /dev/null +++ b/tests/diagnostics/methods/mutating-method-on-rvalue.slang.expected @@ -0,0 +1,8 @@ +result code = -1 +standard error = { +tests/diagnostics/methods/mutating-method-on-rvalue.slang(13): error 30050: mutating method 'increment' cannot be called on an immutable value +tests/diagnostics/methods/mutating-method-on-rvalue.slang(13): 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/methods/mutating-method-on-rvalue.slang(25): error 30050: mutating method 'increment' cannot be called on an immutable value +} +standard output = { +} |
