Skip to content

Commit f32860b

Browse files
authored
Merge pull request #21100 from michaelnebel/csharp14/nameofgenerictype
C# 14: [TEST ONLY] Test for `nameof` generic type.
2 parents ff1ec47 + 0a0cbdb commit f32860b

File tree

6 files changed

+78
-0
lines changed

6 files changed

+78
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
class Program
5+
{
6+
public void M(int x)
7+
{
8+
var test1 = nameof(x);
9+
var test2 = nameof(M);
10+
var test3 = nameof(Program);
11+
var test4 = nameof(String);
12+
var test5 = nameof(List<int>);
13+
var test6 = nameof(List<>);
14+
}
15+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
NameOf.cs:
2+
# 4| [Class] Program
3+
# 6| 6: [Method] M
4+
# 6| -1: [TypeMention] Void
5+
#-----| 2: (Parameters)
6+
# 6| 0: [Parameter] x
7+
# 6| -1: [TypeMention] int
8+
# 7| 4: [BlockStmt] {...}
9+
# 8| 0: [LocalVariableDeclStmt] ... ...;
10+
# 8| 0: [LocalVariableDeclAndInitExpr] String test1 = ...
11+
# 8| -1: [TypeMention] string
12+
# 8| 0: [LocalVariableAccess] access to local variable test1
13+
# 8| 1: [NameOfExpr] nameof(...)
14+
# 8| 0: [ParameterAccess] access to parameter x
15+
# 9| 1: [LocalVariableDeclStmt] ... ...;
16+
# 9| 0: [LocalVariableDeclAndInitExpr] String test2 = ...
17+
# 9| -1: [TypeMention] string
18+
# 9| 0: [LocalVariableAccess] access to local variable test2
19+
# 9| 1: [NameOfExpr] nameof(...)
20+
# 9| 0: [MethodAccess] access to method M
21+
# 10| 2: [LocalVariableDeclStmt] ... ...;
22+
# 10| 0: [LocalVariableDeclAndInitExpr] String test3 = ...
23+
# 10| -1: [TypeMention] string
24+
# 10| 0: [LocalVariableAccess] access to local variable test3
25+
# 10| 1: [NameOfExpr] nameof(...)
26+
# 10| 0: [TypeAccess] access to type Program
27+
# 10| 0: [TypeMention] Program
28+
# 11| 3: [LocalVariableDeclStmt] ... ...;
29+
# 11| 0: [LocalVariableDeclAndInitExpr] String test4 = ...
30+
# 11| -1: [TypeMention] string
31+
# 11| 0: [LocalVariableAccess] access to local variable test4
32+
# 11| 1: [NameOfExpr] nameof(...)
33+
# 11| 0: [TypeAccess] access to type String
34+
# 11| 0: [TypeMention] string
35+
# 12| 4: [LocalVariableDeclStmt] ... ...;
36+
# 12| 0: [LocalVariableDeclAndInitExpr] String test5 = ...
37+
# 12| -1: [TypeMention] string
38+
# 12| 0: [LocalVariableAccess] access to local variable test5
39+
# 12| 1: [NameOfExpr] nameof(...)
40+
# 12| 0: [TypeAccess] access to type List<Int32>
41+
# 12| 0: [TypeMention] List<int>
42+
# 12| 1: [TypeMention] int
43+
# 13| 5: [LocalVariableDeclStmt] ... ...;
44+
# 13| 0: [LocalVariableDeclAndInitExpr] String test6 = ...
45+
# 13| -1: [TypeMention] string
46+
# 13| 0: [LocalVariableAccess] access to local variable test6
47+
# 13| 1: [NameOfExpr] nameof(...)
48+
# 13| 0: [TypeAccess] access to type List`1
49+
# 13| 0: [TypeMention] List<T>
50+
# 13| 1: [TypeMention] T
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shared/PrintAst.ql
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| NameOf.cs:8:21:8:29 | nameof(...) | NameOf.cs:8:28:8:28 | access to parameter x |
2+
| NameOf.cs:9:21:9:29 | nameof(...) | NameOf.cs:9:28:9:28 | access to method M |
3+
| NameOf.cs:10:21:10:35 | nameof(...) | NameOf.cs:10:28:10:34 | access to type Program |
4+
| NameOf.cs:11:21:11:34 | nameof(...) | NameOf.cs:11:28:11:33 | access to type String |
5+
| NameOf.cs:12:21:12:37 | nameof(...) | NameOf.cs:12:28:12:36 | access to type List<Int32> |
6+
| NameOf.cs:13:21:13:34 | nameof(...) | NameOf.cs:13:28:13:33 | access to type List`1 |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import csharp
2+
3+
from NameOfExpr e
4+
select e, e.getAccess()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
semmle-extractor-options: /nostdlib /noconfig
2+
semmle-extractor-options: --load-sources-from-project:${testdir}/../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj

0 commit comments

Comments
 (0)