summaryrefslogtreecommitdiffstats
path: root/tests/diagnostics/mismatching-types.slang
blob: ead1d34ff39654e0a77ea6829dfeb3c57cc9a8fd (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// mismatching-types.slang
//DIAGNOSTIC_TEST:SIMPLE:-target hlsl

Texture1D<float> tex;

struct GenericOuter<T>
{
    struct GenericInner<Q>
    {
        T val;
    };

    struct NonGenericInner
    {
        T val;
    };

    GenericInner<T> g;
    NonGenericInner ng;
};

struct NonGenericOuter
{
    struct GenericInner<T>
    {
        T val;

        struct ReallyNested
        {
            T val;
        };

        ReallyNested n;
    };

    GenericInner<int> i;
    GenericInner<float> f;
};


[shader("compute")]
[numthreads(1, 1, 1)]
void main(uint3 dispatchThreadID : SV_DispatchThreadID)
{    
    GenericOuter<int> a;
    GenericOuter<float> b;
    NonGenericOuter c;
    NonGenericOuter.GenericInner<int> d;
    
    // expected an expression of type 'GenericOuter<int>', got 'int'
    a = 0;

    // expected an expression of type 'GenericOuter<int>.GenericInner<int>', got 'int'
    // explicit conversion from 'int' to 'GenericOuter<int>.GenericInner<int>' is possible
    a.g = 0;

    // expected an expression of type 'GenericOuter<int>.NonGenericInner', got 'int'
    // explicit conversion from 'int' to 'GenericOuter<int>.GenericInner<int>' is possible
    a.ng = 0;
    // expected an expression of type 'GenericOuter<int>.GenericInner<int>', got 'GenericOuter<float>.GenericInner<float>'
    a.g = b.g;
    // expected an expression of type 'GenericOuter<int>.NonGenericInner', got 'GenericOuter<float>.NonGenericInner'
    a.ng = b.ng;
    // expected an expression of type 'NonGenericOuter.GenericInner<int>', got 'int'
    // explicit conversion from 'int' to 'GenericInner<int>' is possible
    c.i = 0;
    // expected an expression of type 'NonGenericOuter.GenericInner<int>', got 'NonGenericOuter.GenericInner<float>'
    c.i = c.f;

    // expected an expression of type 'NonGenericOuter.GenericInner<int>.ReallyNested', got 'int'
    // explicit conversion from 'int' to 'GenericInner<int>.ReallyNested' is possible
    c.i.n = 0;
    // OK
    c.i.n.val = 0;
    // OK
    d.val = 0;
    // OK
    c.i = d;

    // expected an expression of type 'Texture1D<int>', got 'Texture1D<float>'
    Texture1D<int> t1 = tex;
    // expected an expression of type 'Texture2D<float>', got 'Texture1D<float>'
    Texture2D<float> t2 = tex;
}