summaryrefslogtreecommitdiff
path: root/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang
blob: 2dbe45ccb04b8f0448ca44cb8faf2f41727da842 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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);
}