summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/generics/dependent-generic-2.slang
blob: 909669827df15c95c57af461a4decec67a3bf52a (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
43
44
45
46
47
48
49
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -output-using-type

// Test that we can infer a generic type parameter from the base type of a dependent generic argument.

interface IFoo : IDefaultInitializable
{
    int get();
}

struct Foo : IFoo
{
    int get()
    {
        return 1;
    }
}

interface IBar<T : IFoo>
{
    int getVal();
}

struct Bar<T : IFoo> : IBar<T>
{
    int getVal()
    {
        T t = T();
        return t.get();
    }
}

int test<T:IFoo, B : IBar<T>>(B b)
{
    return b.getVal();
}

//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)
{
    Bar<Foo> obj2;
    let result = test(obj2);

    // CHECK: 1
    outputBuffer[0] = result;
}