summaryrefslogtreecommitdiff
path: root/tests/src/JIT/Generics/Instantiation/Classes/BaseClass03.cs
blob: 92578f363b36af2d9ec8e592cc44a8e5847b7368 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//

using System;

public struct ValX0 { }
public struct ValY0 { }
public struct ValX1<T> { }
public struct ValY1<T> { }
public struct ValX2<T, U> { }
public struct ValY2<T, U> { }
public struct ValX3<T, U, V> { }
public struct ValY3<T, U, V> { }
public class RefX0 { }
public class RefY0 { }
public class RefX1<T> { }
public class RefY1<T> { }
public class RefX2<T, U> { }
public class RefY2<T, U> { }
public class RefX3<T, U, V> { }
public class RefY3<T, U, V> { }


public class GenBase<T, U>
{
    public T Fld1;
    public U Fld2;

    public GenBase(T fld1, U fld2)
    {
        Fld1 = fld1;
        Fld2 = fld2;
    }

    public bool InstVerify(System.Type t1, System.Type t2)
    {
        bool result = true;

        if (!(Fld1.GetType().Equals(t1)))
        {
            result = false;
            Console.WriteLine("Failed to verify type of Fld1 in: " + typeof(GenBase<T, U>));
        }

        if (!(Fld2.GetType().Equals(t2)))
        {
            result = false;
            Console.WriteLine("Failed to verify type of Fld2 in: " + typeof(GenBase<T, U>));
        }

        return result;
    }
}


public class Gen<T> : GenBase<T, int>
{
    public Gen(T fld1) : base(fld1, 1) { }

    public bool InstVerify(System.Type t1)
    {
        return base.InstVerify(t1, typeof(int));
    }
}

public class Test
{
    public static int counter = 0;
    public static bool result = true;
    public static void Eval(bool exp)
    {
        counter++;
        if (!exp)
        {
            result = exp;
            Console.WriteLine("Test Failed at location: " + counter);
        }

    }

    public static int Main()
    {
        Eval((new Gen<int>(new int())).InstVerify(typeof(int)));
        Eval((new Gen<double>(new double())).InstVerify(typeof(double)));
        Eval((new Gen<string>("string")).InstVerify(typeof(string)));
        Eval((new Gen<object>(new object())).InstVerify(typeof(object)));
        Eval((new Gen<Guid>(new Guid())).InstVerify(typeof(Guid)));

        Eval((new Gen<int[]>(new int[1])).InstVerify(typeof(int[])));
        Eval((new Gen<double[,]>(new double[1, 1])).InstVerify(typeof(double[,])));
        Eval((new Gen<string[][][]>(new string[1][][])).InstVerify(typeof(string[][][])));
        Eval((new Gen<object[, , ,]>(new object[1, 1, 1, 1])).InstVerify(typeof(object[, , ,])));
        Eval((new Gen<Guid[][, , ,][]>(new Guid[1][, , ,][])).InstVerify(typeof(Guid[][, , ,][])));

        Eval((new Gen<RefX1<int>[]>(new RefX1<int>[] { })).InstVerify(typeof(RefX1<int>[])));
        Eval((new Gen<RefX1<double>[,]>(new RefX1<double>[1, 1])).InstVerify(typeof(RefX1<double>[,])));
        Eval((new Gen<RefX1<string>[][][]>(new RefX1<string>[1][][])).InstVerify(typeof(RefX1<string>[][][])));
        Eval((new Gen<RefX1<object>[, , ,]>(new RefX1<object>[1, 1, 1, 1])).InstVerify(typeof(RefX1<object>[, , ,])));
        Eval((new Gen<RefX1<Guid>[][, , ,][]>(new RefX1<Guid>[1][, , ,][])).InstVerify(typeof(RefX1<Guid>[][, , ,][])));

        Eval((new Gen<RefX2<int, int>[]>(new RefX2<int, int>[] { })).InstVerify(typeof(RefX2<int, int>[])));
        Eval((new Gen<RefX2<double, double>[,]>(new RefX2<double, double>[1, 1])).InstVerify(typeof(RefX2<double, double>[,])));
        Eval((new Gen<RefX2<string, string>[][][]>(new RefX2<string, string>[1][][])).InstVerify(typeof(RefX2<string, string>[][][])));
        Eval((new Gen<RefX2<object, object>[, , ,]>(new RefX2<object, object>[1, 1, 1, 1])).InstVerify(typeof(RefX2<object, object>[, , ,])));
        Eval((new Gen<RefX2<Guid, Guid>[][, , ,][]>(new RefX2<Guid, Guid>[1][, , ,][])).InstVerify(typeof(RefX2<Guid, Guid>[][, , ,][])));

        Eval((new Gen<ValX1<int>[]>(new ValX1<int>[] { })).InstVerify(typeof(ValX1<int>[])));
        Eval((new Gen<ValX1<double>[,]>(new ValX1<double>[1, 1])).InstVerify(typeof(ValX1<double>[,])));
        Eval((new Gen<ValX1<string>[][][]>(new ValX1<string>[1][][])).InstVerify(typeof(ValX1<string>[][][])));
        Eval((new Gen<ValX1<object>[, , ,]>(new ValX1<object>[1, 1, 1, 1])).InstVerify(typeof(ValX1<object>[, , ,])));
        Eval((new Gen<ValX1<Guid>[][, , ,][]>(new ValX1<Guid>[1][, , ,][])).InstVerify(typeof(ValX1<Guid>[][, , ,][])));

        Eval((new Gen<ValX2<int, int>[]>(new ValX2<int, int>[] { })).InstVerify(typeof(ValX2<int, int>[])));
        Eval((new Gen<ValX2<double, double>[,]>(new ValX2<double, double>[1, 1])).InstVerify(typeof(ValX2<double, double>[,])));
        Eval((new Gen<ValX2<string, string>[][][]>(new ValX2<string, string>[1][][])).InstVerify(typeof(ValX2<string, string>[][][])));
        Eval((new Gen<ValX2<object, object>[, , ,]>(new ValX2<object, object>[1, 1, 1, 1])).InstVerify(typeof(ValX2<object, object>[, , ,])));

        Eval((new Gen<ValX2<Guid, Guid>[][, , ,][]>(new ValX2<Guid, Guid>[1][, , ,][])).InstVerify(typeof(ValX2<Guid, Guid>[][, , ,][])));

        Eval((new Gen<RefX1<int>>(new RefX1<int>())).InstVerify(typeof(RefX1<int>)));
        Eval((new Gen<RefX1<ValX1<int>>>(new RefX1<ValX1<int>>())).InstVerify(typeof(RefX1<ValX1<int>>)));
        Eval((new Gen<RefX2<int, string>>(new RefX2<int, string>())).InstVerify(typeof(RefX2<int, string>)));
        Eval((new Gen<RefX3<int, string, Guid>>(new RefX3<int, string, Guid>())).InstVerify(typeof(RefX3<int, string, Guid>)));

        Eval((new Gen<RefX1<RefX1<int>>>(new RefX1<RefX1<int>>())).InstVerify(typeof(RefX1<RefX1<int>>)));
        Eval((new Gen<RefX1<RefX1<RefX1<string>>>>(new RefX1<RefX1<RefX1<string>>>())).InstVerify(typeof(RefX1<RefX1<RefX1<string>>>)));
        Eval((new Gen<RefX1<RefX1<RefX1<RefX1<Guid>>>>>(new RefX1<RefX1<RefX1<RefX1<Guid>>>>())).InstVerify(typeof(RefX1<RefX1<RefX1<RefX1<Guid>>>>)));

        Eval((new Gen<RefX1<RefX2<int, string>>>(new RefX1<RefX2<int, string>>())).InstVerify(typeof(RefX1<RefX2<int, string>>)));
        Eval((new Gen<RefX2<RefX2<RefX1<int>, RefX3<int, string, RefX1<RefX2<int, string>>>>, RefX2<RefX1<int>, RefX3<int, string, RefX1<RefX2<int, string>>>>>>(new RefX2<RefX2<RefX1<int>, RefX3<int, string, RefX1<RefX2<int, string>>>>, RefX2<RefX1<int>, RefX3<int, string, RefX1<RefX2<int, string>>>>>())).InstVerify(typeof(RefX2<RefX2<RefX1<int>, RefX3<int, string, RefX1<RefX2<int, string>>>>, RefX2<RefX1<int>, RefX3<int, string, RefX1<RefX2<int, string>>>>>)));
        Eval((new Gen<RefX3<RefX1<int[][, , ,]>, RefX2<object[, , ,][][], Guid[][][]>, RefX3<double[, , , , , , , , , ,], Guid[][][][, , , ,][, , , ,][][][], string[][][][][][][][][][][]>>>(new RefX3<RefX1<int[][, , ,]>, RefX2<object[, , ,][][], Guid[][][]>, RefX3<double[, , , , , , , , , ,], Guid[][][][, , , ,][, , , ,][][][], string[][][][][][][][][][][]>>())).InstVerify(typeof(RefX3<RefX1<int[][, , ,]>, RefX2<object[, , ,][][], Guid[][][]>, RefX3<double[, , , , , , , , , ,], Guid[][][][, , , ,][, , , ,][][][], string[][][][][][][][][][][]>>)));

        Eval((new Gen<ValX1<int>>(new ValX1<int>())).InstVerify(typeof(ValX1<int>)));
        Eval((new Gen<ValX1<RefX1<int>>>(new ValX1<RefX1<int>>())).InstVerify(typeof(ValX1<RefX1<int>>)));
        Eval((new Gen<ValX2<int, string>>(new ValX2<int, string>())).InstVerify(typeof(ValX2<int, string>)));
        Eval((new Gen<ValX3<int, string, Guid>>(new ValX3<int, string, Guid>())).InstVerify(typeof(ValX3<int, string, Guid>)));

        Eval((new Gen<ValX1<ValX1<int>>>(new ValX1<ValX1<int>>())).InstVerify(typeof(ValX1<ValX1<int>>)));
        Eval((new Gen<ValX1<ValX1<ValX1<string>>>>(new ValX1<ValX1<ValX1<string>>>())).InstVerify(typeof(ValX1<ValX1<ValX1<string>>>)));
        Eval((new Gen<ValX1<ValX1<ValX1<ValX1<Guid>>>>>(new ValX1<ValX1<ValX1<ValX1<Guid>>>>())).InstVerify(typeof(ValX1<ValX1<ValX1<ValX1<Guid>>>>)));

        Eval((new Gen<ValX1<ValX2<int, string>>>(new ValX1<ValX2<int, string>>())).InstVerify(typeof(ValX1<ValX2<int, string>>)));
        Eval((new Gen<ValX2<ValX2<ValX1<int>, ValX3<int, string, ValX1<ValX2<int, string>>>>, ValX2<ValX1<int>, ValX3<int, string, ValX1<ValX2<int, string>>>>>>(new ValX2<ValX2<ValX1<int>, ValX3<int, string, ValX1<ValX2<int, string>>>>, ValX2<ValX1<int>, ValX3<int, string, ValX1<ValX2<int, string>>>>>())).InstVerify(typeof(ValX2<ValX2<ValX1<int>, ValX3<int, string, ValX1<ValX2<int, string>>>>, ValX2<ValX1<int>, ValX3<int, string, ValX1<ValX2<int, string>>>>>)));
        Eval((new Gen<ValX3<ValX1<int[][, , ,]>, ValX2<object[, , ,][][], Guid[][][]>, ValX3<double[, , , , , , , , , ,], Guid[][][][, , , ,][, , , ,][][][], string[][][][][][][][][][][]>>>(new ValX3<ValX1<int[][, , ,]>, ValX2<object[, , ,][][], Guid[][][]>, ValX3<double[, , , , , , , , , ,], Guid[][][][, , , ,][, , , ,][][][], string[][][][][][][][][][][]>>())).InstVerify(typeof(ValX3<ValX1<int[][, , ,]>, ValX2<object[, , ,][][], Guid[][][]>, ValX3<double[, , , , , , , , , ,], Guid[][][][, , , ,][, , , ,][][][], string[][][][][][][][][][][]>>)));



        if (result)
        {
            Console.WriteLine("Test Passed");
            return 100;
        }
        else
        {
            Console.WriteLine("Test Failed");
            return 1;
        }
    }

}