summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/generics/generic-overload-disambiguation.slang
blob: 57d7a6d7e5bc61ec55c680ab480e38c6e04172d4 (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
//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 calls to overloaded generic functions can be resolved to prefer the
// generic candidate with more specialized constraints.
interface IBase
{
    float get();
}
interface IDerived : IBase
{

}
float process<T>(T v)
{
    return 0.0;
}
float process<T : IBase>(T v)
{
    return v.get();
}

float process<T : IDerived>(T v)
{
    return v.get() + 1.0;
}

struct D : IDerived
{
    float get() { return 1.0; }
}

//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<float> outputBuffer;

[numthreads(1,1,1)]
void computeMain()
{
    D d;
    outputBuffer[0] = process(d);
    // CHECK: 2.0
}