yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Yong HeEnsure generic constraints are checked before inner extension. (#7685)90c34e3db

master
766 B52 linesraw
1//TEST:INTERPRET(filecheck=CHECK):
2interface IGen<A>
3{
4    associatedtype TB;
5    TB getVal();
6}
7
8struct Foo1<A> : IGen<A>
9{
10    typealias TB = int;
11    int val = 0;
12    TB getVal()
13    {
14       return val; 
15    }
16}
17
18struct Foo2<A> : IGen<A>
19{
20    typealias TB = int;
21    int val = 0;
22    TB getVal()
23    {
24       return val; 
25    }
26}
27
28struct Logic<A1, C1 : IGen<A1>, C2 : IGen<A1>>
29{
30    int val = 0;
31}
32
33extension<A, C1, C2> Logic<A, C1, C2>
34    where C1 : IGen<A>
35    where C2 : IGen<A>
36    where C1.TB == C2.TB
37{
38    [mutating]
39    void setVal(int dataIn)
40    {
41        val = dataIn;
42    }
43}
44
45void main()
46{
47    Logic<int, Foo1<int>, Foo2<int>> logic;
48    logic.setVal(42);
49    int result = logic.val;
50    printf("Result: %d\n", result);
51    // CHECK: Result: 42
52}