Skip to content

Commit 8a01023

Browse files
committed
C#: Add more generics tests
1 parent 4f77430 commit 8a01023

File tree

3 files changed

+193
-0
lines changed

3 files changed

+193
-0
lines changed

csharp/ql/test/library-tests/generics/Generics.expected

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ test2
55
test3
66
| generics.cs:13:18:13:21 | A<X> | generics.cs:13:18:13:21 | A<> |
77
test4
8+
| Nesting.cs:12:18:12:18 | C | Unbound generic class with inconsistent name |
9+
| Nesting.cs:12:18:12:18 | C | Unbound generic class with inconsistent name |
10+
| Nesting.cs:12:18:12:18 | C | Unbound generic class with inconsistent name |
811
test5
912
test6
1013
| generics.cs:13:18:13:21 | A<T> | generics.cs:22:18:22:21 | B<> | generics.cs:22:18:22:21 | B<X> | generics.cs:25:23:25:24 | at |
1114
test7
15+
| Nesting.cs:1:14:1:18 | A<String> | Nesting.cs:6:18:6:22 | B<String> |
16+
| Nesting.cs:1:14:1:18 | A<String> | generics.cs:22:18:22:21 | B<String> |
17+
| generics.cs:13:18:13:21 | A<String> | Nesting.cs:6:18:6:22 | B<String> |
1218
| generics.cs:13:18:13:21 | A<String> | generics.cs:22:18:22:21 | B<String> |
1319
test8
1420
| generics.cs:22:18:22:21 | B<String> | generics.cs:31:21:31:29 | fooParams |
@@ -35,6 +41,19 @@ test17
3541
| generics.cs:134:11:134:16 | Subtle | generics.cs:137:24:137:24 | X | generics.cs:137:21:137:25 | fs | generics.cs:139:24:139:24 | X | generics.cs:139:21:139:25 | fs | 1 |
3642
| generics.cs:134:11:134:16 | Subtle | generics.cs:139:24:139:24 | X | generics.cs:139:21:139:25 | fs | generics.cs:137:24:137:24 | X | generics.cs:137:21:137:25 | fs | 2 |
3743
test18
44+
| Nesting.cs:1:14:1:18 | A<> | Nesting.cs:3:17:3:19 | MA1 | Nesting.cs:3:24:3:24 | x | 0 | T1 | 1 | 1 |
45+
| Nesting.cs:1:14:1:18 | A<> | Nesting.cs:4:17:4:23 | MA2 | Nesting.cs:4:28:4:28 | x | 0 | T1 | 2 | 2 |
46+
| Nesting.cs:1:14:1:18 | A<> | Nesting.cs:4:17:4:23 | MA2 | Nesting.cs:4:34:4:34 | y | 0 | T2 | 2 | 2 |
47+
| Nesting.cs:1:14:1:18 | A<Int32> | Nesting.cs:3:17:3:19 | MA1 | Nesting.cs:3:24:3:24 | x | 0 | Int32 | 1 | 1 |
48+
| Nesting.cs:1:14:1:18 | A<Int32> | Nesting.cs:4:17:4:23 | MA2 | Nesting.cs:4:28:4:28 | x | 0 | Int32 | 2 | 2 |
49+
| Nesting.cs:1:14:1:18 | A<Int32> | Nesting.cs:4:17:4:23 | MA2 | Nesting.cs:4:28:4:28 | x | 1 | Int32 | 2 | 2 |
50+
| Nesting.cs:1:14:1:18 | A<Int32> | Nesting.cs:4:17:4:23 | MA2 | Nesting.cs:4:34:4:34 | y | 0 | T2 | 2 | 2 |
51+
| Nesting.cs:1:14:1:18 | A<Int32> | Nesting.cs:4:17:4:23 | MA2 | Nesting.cs:4:34:4:34 | y | 1 | String | 2 | 2 |
52+
| Nesting.cs:1:14:1:18 | A<String> | Nesting.cs:3:17:3:19 | MA1 | Nesting.cs:3:24:3:24 | x | 0 | String | 1 | 1 |
53+
| Nesting.cs:1:14:1:18 | A<String> | Nesting.cs:4:17:4:23 | MA2 | Nesting.cs:4:28:4:28 | x | 0 | String | 2 | 2 |
54+
| Nesting.cs:1:14:1:18 | A<String> | Nesting.cs:4:17:4:23 | MA2 | Nesting.cs:4:28:4:28 | x | 1 | String | 2 | 2 |
55+
| Nesting.cs:1:14:1:18 | A<String> | Nesting.cs:4:17:4:23 | MA2 | Nesting.cs:4:34:4:34 | y | 0 | T2 | 2 | 2 |
56+
| Nesting.cs:1:14:1:18 | A<String> | Nesting.cs:4:17:4:23 | MA2 | Nesting.cs:4:34:4:34 | y | 1 | Int32 | 2 | 2 |
3857
| generics.cs:13:18:13:21 | A<> | generics.cs:18:18:18:23 | bar | generics.cs:18:27:18:27 | x | 0 | X | 2 | 2 |
3958
| generics.cs:13:18:13:21 | A<> | generics.cs:18:18:18:23 | bar | generics.cs:18:32:18:32 | t | 0 | T | 2 | 2 |
4059
| generics.cs:13:18:13:21 | A<Int32> | generics.cs:18:18:18:23 | bar | generics.cs:18:27:18:27 | x | 0 | X | 2 | 2 |
@@ -68,4 +87,97 @@ test25
6887
| generics.cs:157:23:157:29 | CM3 |
6988
test26
7089
test27
90+
| Nesting.cs:6:18:6:22 | B<Int32> | Nesting.cs:6:18:6:22 | B<> | Nesting.cs:6:18:6:22 | B<> |
91+
| Nesting.cs:6:18:6:22 | B<String> | Nesting.cs:6:18:6:22 | B<> | Nesting.cs:6:18:6:22 | B<> |
92+
| Nesting.cs:17:22:17:26 | D<Boolean> | Nesting.cs:17:22:17:26 | D<> | Nesting.cs:17:22:17:26 | D<> |
93+
| Nesting.cs:17:22:17:26 | D<Decimal> | Nesting.cs:17:22:17:26 | D<> | Nesting.cs:17:22:17:26 | D<> |
7194
| generics.cs:51:22:51:29 | Inner<String> | generics.cs:51:22:51:29 | Inner<> | generics.cs:51:22:51:29 | Inner<> |
95+
test28
96+
| Nesting.cs:4:17:4:23 | MA2 | A<>.MA2<T2>(T1, T2) |
97+
| Nesting.cs:4:17:4:23 | MA2 | A<Int32>.MA2<T2>(int, T2) |
98+
| Nesting.cs:4:17:4:23 | MA2 | A<String>.MA2<T2>(string, T2) |
99+
| Nesting.cs:6:18:6:22 | B<> | A<>.B<T3> |
100+
| Nesting.cs:6:18:6:22 | B<> | A<Int32>.B<T3> |
101+
| Nesting.cs:6:18:6:22 | B<> | A<String>.B<T3> |
102+
| Nesting.cs:9:21:9:27 | MB2 | A<>.B<>.MB2<T4>(T1, T3, T4) |
103+
| Nesting.cs:9:21:9:27 | MB2 | A<Int32>.B<String>.MB2<T4>(int, string, T4) |
104+
| Nesting.cs:9:21:9:27 | MB2 | A<String>.B<Int32>.MB2<T4>(string, int, T4) |
105+
| Nesting.cs:12:18:12:18 | C | A<>.<> |
106+
| Nesting.cs:12:18:12:18 | C | A<Int32>.<> |
107+
| Nesting.cs:12:18:12:18 | C | A<String>.<> |
108+
| Nesting.cs:15:21:15:27 | MC2 | A<>.C.MC2<T5>(T1, T5) |
109+
| Nesting.cs:15:21:15:27 | MC2 | A<Int32>.C.MC2<T5>(int, T5) |
110+
| Nesting.cs:15:21:15:27 | MC2 | A<String>.C.MC2<T5>(string, T5) |
111+
| Nesting.cs:17:22:17:26 | D<> | A<>.C.D<T6> |
112+
| Nesting.cs:17:22:17:26 | D<> | A<Int32>.C.D<T6> |
113+
| Nesting.cs:17:22:17:26 | D<> | A<String>.C.D<T6> |
114+
| Nesting.cs:20:25:20:31 | MD2 | A<>.C.D<>.MD2<T7>(T1, T6, T7) |
115+
| Nesting.cs:20:25:20:31 | MD2 | A<Int32>.C.D<Boolean>.MD2<T7>(int, bool, T7) |
116+
| Nesting.cs:20:25:20:31 | MD2 | A<String>.C.D<Decimal>.MD2<T7>(string, decimal, T7) |
117+
| generics.cs:16:27:16:58 | GenericDelegateInGenericClass<> | generics.A<>.GenericDelegateInGenericClass<U>(T, U) |
118+
| generics.cs:16:27:16:58 | GenericDelegateInGenericClass<> | generics.A<Int32>.GenericDelegateInGenericClass<U>(int, U) |
119+
| generics.cs:16:27:16:58 | GenericDelegateInGenericClass<> | generics.A<String>.GenericDelegateInGenericClass<U>(string, U) |
120+
| generics.cs:18:18:18:23 | bar | generics.A<>.bar<X>(X, T) |
121+
| generics.cs:18:18:18:23 | bar | generics.A<Int32>.bar<X>(X, int) |
122+
| generics.cs:18:18:18:23 | bar | generics.A<String>.bar<X>(X, string) |
123+
| generics.cs:45:14:45:17 | f | generics.B<>.f<X>() |
124+
| generics.cs:45:14:45:17 | f | generics.B<Object>.f<X>() |
125+
| generics.cs:45:14:45:17 | f | generics.B<String>.f<X>() |
126+
| generics.cs:45:14:45:17 | f | generics.B<X>.f<X>() |
127+
| generics.cs:51:22:51:29 | Inner<> | generics.Outer<>.Inner<U> |
128+
| generics.cs:51:22:51:29 | Inner<> | generics.Outer<Object>.Inner<U> |
129+
| generics.cs:137:21:137:25 | fs | generics.Subtle.fs<X>(int) |
130+
| generics.cs:139:21:139:25 | fs | generics.Subtle.fs<X>(int, int) |
131+
| generics.cs:147:14:147:14 | E | generics.Param<>.<> |
132+
| generics.cs:152:14:152:19 | CM1 | generics.ConstructedMethods.CM1<T>() |
133+
| generics.cs:153:11:153:16 | CM2 | generics.ConstructedMethods.CM2<T>(T) |
134+
| generics.cs:155:15:155:23 | Class<> | generics.ConstructedMethods.Class<T1> |
135+
| generics.cs:157:23:157:29 | CM3 | generics.ConstructedMethods.Class<>.CM3<T2>(T2, T1) |
136+
| generics.cs:157:23:157:29 | CM3 | generics.ConstructedMethods.Class<Double>.CM3<T2>(T2, double) |
137+
| generics.cs:157:23:157:29 | CM3 | generics.ConstructedMethods.Class<Int32>.CM3<T2>(T2, int) |
138+
test29
139+
| Nesting.cs:4:17:4:23 | MA2 | A<Int32>.MA2<string>(int, string) |
140+
| Nesting.cs:4:17:4:23 | MA2 | A<String>.MA2<int>(string, int) |
141+
| Nesting.cs:6:18:6:22 | B<Int32> | A<String>.B<Int32> |
142+
| Nesting.cs:6:18:6:22 | B<String> | A<Int32>.B<String> |
143+
| Nesting.cs:9:21:9:27 | MB2 | A<Int32>.B<String>.MB2<bool>(int, string, bool) |
144+
| Nesting.cs:9:21:9:27 | MB2 | A<String>.B<Int32>.MB2<bool>(string, int, bool) |
145+
| Nesting.cs:15:21:15:27 | MC2 | A<Int32>.C.MC2<bool>(int, bool) |
146+
| Nesting.cs:15:21:15:27 | MC2 | A<String>.C.MC2<bool>(string, bool) |
147+
| Nesting.cs:17:22:17:26 | D<Boolean> | A<Int32>.C.D<Boolean> |
148+
| Nesting.cs:17:22:17:26 | D<Decimal> | A<String>.C.D<Decimal> |
149+
| Nesting.cs:20:25:20:31 | MD2 | A<Int32>.C.D<Boolean>.MD2<string>(int, bool, string) |
150+
| Nesting.cs:20:25:20:31 | MD2 | A<String>.C.D<Decimal>.MD2<bool>(string, decimal, bool) |
151+
| generics.cs:18:18:18:23 | bar | generics.A<Int32>.bar<Test>(Test, int) |
152+
| generics.cs:18:18:18:23 | bar | generics.A<String>.bar<int>(int, string) |
153+
| generics.cs:51:22:51:29 | Inner<String> | generics.Outer<Object>.Inner<String> |
154+
| generics.cs:152:14:152:19 | CM1 | generics.ConstructedMethods.CM1<double>() |
155+
| generics.cs:152:14:152:19 | CM1 | generics.ConstructedMethods.CM1<int>() |
156+
| generics.cs:153:11:153:16 | CM2 | generics.ConstructedMethods.CM2<double>(double) |
157+
| generics.cs:153:11:153:16 | CM2 | generics.ConstructedMethods.CM2<int>(int) |
158+
| generics.cs:155:15:155:23 | Class<Double> | generics.ConstructedMethods.Class<Double> |
159+
| generics.cs:155:15:155:23 | Class<Int32> | generics.ConstructedMethods.Class<Int32> |
160+
| generics.cs:157:23:157:29 | CM3 | generics.ConstructedMethods.Class<Double>.CM3<double>(double, double) |
161+
| generics.cs:157:23:157:29 | CM3 | generics.ConstructedMethods.Class<Int32>.CM3<double>(double, int) |
162+
test30
163+
| Nesting.cs:3:17:3:19 | MA1 | A<Int32>.MA1(int) |
164+
| Nesting.cs:3:17:3:19 | MA1 | A<String>.MA1(string) |
165+
| Nesting.cs:8:21:8:23 | MB1 | A<Int32>.B<String>.MB1(int, string) |
166+
| Nesting.cs:8:21:8:23 | MB1 | A<String>.B<Int32>.MB1(string, int) |
167+
| Nesting.cs:14:21:14:23 | MC1 | A<Int32>.C.MC1(int) |
168+
| Nesting.cs:14:21:14:23 | MC1 | A<String>.C.MC1(string) |
169+
| Nesting.cs:19:25:19:27 | MD1 | A<Int32>.C.D<Boolean>.MD1(int, bool) |
170+
| Nesting.cs:19:25:19:27 | MD1 | A<String>.C.D<Decimal>.MD1(string, decimal) |
171+
| Nesting.cs:24:10:24:18 | Construct | A<Int32>.Construct() |
172+
| Nesting.cs:24:10:24:18 | Construct | A<String>.Construct() |
173+
| generics.cs:29:21:29:23 | foo | generics.B<Object>.foo() |
174+
| generics.cs:29:21:29:23 | foo | generics.B<String>.foo() |
175+
| generics.cs:29:21:29:23 | foo | generics.B<X>.foo() |
176+
| generics.cs:31:21:31:29 | fooParams | generics.B<Object>.fooParams(params Object[]) |
177+
| generics.cs:31:21:31:29 | fooParams | generics.B<String>.fooParams(params String[]) |
178+
| generics.cs:31:21:31:29 | fooParams | generics.B<X>.fooParams(params X[]) |
179+
| generics.cs:33:28:33:36 | staticFoo | generics.B<Object>.staticFoo() |
180+
| generics.cs:33:28:33:36 | staticFoo | generics.B<String>.staticFoo() |
181+
| generics.cs:33:28:33:36 | staticFoo | generics.B<X>.staticFoo() |
182+
| generics.cs:175:14:175:16 | set | generics.Interface<T>.set(T) |
183+
test31

csharp/ql/test/library-tests/generics/Generics.ql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,26 @@ query predicate test27(ConstructedType ct, UnboundGenericType ugt, UnboundGeneri
227227
sourceDecl = ct.getSourceDeclaration() and
228228
ugt != sourceDecl
229229
}
230+
231+
query predicate test28(UnboundGeneric ug, string s) {
232+
ug.fromSource() and
233+
s = ug.getQualifiedNameWithTypes()
234+
}
235+
236+
query predicate test29(ConstructedGeneric cg, string s) {
237+
cg.fromSource() and
238+
s = cg.getQualifiedNameWithTypes()
239+
}
240+
241+
query predicate test30(Declaration d, string s) {
242+
d.fromSource() and
243+
d instanceof @generic and
244+
s = d.getQualifiedNameWithTypes() and
245+
d != d.getSourceDeclaration() and
246+
not d instanceof Generic
247+
}
248+
249+
query predicate test31(ConstructedGeneric cg, string s) {
250+
not exists(cg.getUnboundGeneric()) and
251+
s = "Missing unbound generic"
252+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
public class A<T1>
2+
{
3+
public void MA1(T1 x) { }
4+
public void MA2<T2>(T1 x, T2 y) { }
5+
6+
public class B<T3>
7+
{
8+
public void MB1(T1 x, T3 y) { }
9+
public void MB2<T4>(T1 x, T3 y, T4 z) { }
10+
}
11+
12+
public class C
13+
{
14+
public void MC1(T1 x) { }
15+
public void MC2<T5>(T1 x, T5 y) { }
16+
17+
public class D<T6>
18+
{
19+
public void MD1(T1 x, T6 y) { }
20+
public void MD2<T7>(T1 x, T6 y, T7 z) { }
21+
}
22+
}
23+
24+
void Construct()
25+
{
26+
var a1 = new A<int>();
27+
a1.MA1(0);
28+
a1.MA2(0, "");
29+
30+
var a2 = new A<string>();
31+
a2.MA1("");
32+
a2.MA2("", 0);
33+
34+
var b1 = new A<int>.B<string>();
35+
b1.MB1(0, "");
36+
b1.MB2(0, "", false);
37+
38+
var b2 = new A<string>.B<int>();
39+
b2.MB1("", 0);
40+
b2.MB2("", 0, false);
41+
42+
var c1 = new A<int>.C();
43+
c1.MC1(0);
44+
c1.MC2(0, false);
45+
46+
var c2 = new A<string>.C();
47+
c2.MC1("");
48+
c2.MC2("", false);
49+
50+
var d1 = new A<int>.C.D<bool>();
51+
d1.MD1(0, false);
52+
d1.MD2(0, false, "");
53+
54+
var d2 = new A<string>.C.D<decimal>();
55+
d2.MD1("", 0m);
56+
d2.MD2("", 0m, false);
57+
}
58+
}

0 commit comments

Comments
 (0)