Skip to content

Commit 3cd2024

Browse files
authored
Merge pull request github#12060 from michaelnebel/csharp11/nameof
C# 11: Nameof on attribute declarations.
2 parents 62158c5 + 4089845 commit 3cd2024

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
3+
public class MyAttributeTestClass
4+
{
5+
public class MyAttribute : Attribute
6+
{
7+
public readonly string S;
8+
public MyAttribute(string s) => S = s;
9+
}
10+
11+
[MyAttribute(nameof(T))]
12+
public void M1<T>(string x) { }
13+
14+
[return: MyAttribute(nameof(y))]
15+
public string M2(string y) => y;
16+
17+
public object M3([MyAttribute(nameof(z))] string z) => z;
18+
19+
public object M4<S>([MyAttribute(nameof(S))] string z) => z;
20+
}

csharp/ql/test/library-tests/csharp11/PrintAst.expected

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,70 @@ ListPattern.cs:
165165
# 33| 13: [BreakStmt] break;
166166
# 34| 14: [DefaultCase] default:
167167
# 35| 15: [BreakStmt] break;
168+
NameofScope.cs:
169+
# 3| [Class] MyAttributeTestClass
170+
# 5| 5: [Class] MyAttribute
171+
#-----| 3: (Base types)
172+
# 5| 0: [TypeMention] Attribute
173+
# 7| 4: [Field] S
174+
# 7| -1: [TypeMention] string
175+
# 8| 5: [InstanceConstructor] MyAttribute
176+
#-----| 2: (Parameters)
177+
# 8| 0: [Parameter] s
178+
# 8| -1: [TypeMention] string
179+
# 8| 4: [AssignExpr] ... = ...
180+
# 8| 0: [FieldAccess] access to field S
181+
# 8| 1: [ParameterAccess] access to parameter s
182+
# 12| 6: [Method] M1<>
183+
# 12| -1: [TypeMention] Void
184+
#-----| 0: (Attributes)
185+
# 11| 1: [DefaultAttribute] [My(...)]
186+
# 11| -1: [TypeMention] MyAttribute
187+
# 11| 0: [NameOfExpr] nameof(...)
188+
# 11| 0: [TypeAccess] access to type T
189+
# 11| 0: [TypeMention] T
190+
#-----| 1: (Type parameters)
191+
# 12| 0: [TypeParameter] T
192+
#-----| 2: (Parameters)
193+
# 12| 0: [Parameter] x
194+
# 12| -1: [TypeMention] string
195+
# 12| 4: [BlockStmt] {...}
196+
# 15| 7: [Method] M2
197+
# 15| -1: [TypeMention] string
198+
#-----| 0: (Attributes)
199+
# 14| 1: [ReturnAttribute] [return: My(...)]
200+
# 14| -1: [TypeMention] MyAttribute
201+
# 14| 0: [NameOfExpr] nameof(...)
202+
# 14| 0: [ParameterAccess] access to parameter y
203+
#-----| 2: (Parameters)
204+
# 15| 0: [Parameter] y
205+
# 15| -1: [TypeMention] string
206+
# 15| 4: [ParameterAccess] access to parameter y
207+
# 17| 8: [Method] M3
208+
# 17| -1: [TypeMention] object
209+
#-----| 2: (Parameters)
210+
# 17| 0: [Parameter] z
211+
# 17| -1: [TypeMention] string
212+
#-----| 0: (Attributes)
213+
# 17| 1: [DefaultAttribute] [My(...)]
214+
# 17| -1: [TypeMention] MyAttribute
215+
# 17| 0: [NameOfExpr] nameof(...)
216+
# 17| 0: [ParameterAccess] access to parameter z
217+
# 17| 4: [ParameterAccess] access to parameter z
218+
# 19| 9: [Method] M4<>
219+
# 19| -1: [TypeMention] object
220+
#-----| 1: (Type parameters)
221+
# 19| 0: [TypeParameter] S
222+
#-----| 2: (Parameters)
223+
# 19| 0: [Parameter] z
224+
# 19| -1: [TypeMention] string
225+
#-----| 0: (Attributes)
226+
# 19| 1: [DefaultAttribute] [My(...)]
227+
# 19| -1: [TypeMention] MyAttribute
228+
# 19| 0: [NameOfExpr] nameof(...)
229+
# 19| 0: [TypeAccess] access to type S
230+
# 19| 0: [TypeMention] S
231+
# 19| 4: [ParameterAccess] access to parameter z
168232
NativeInt.cs:
169233
# 1| [Class] NativeInt
170234
# 3| 5: [Method] M1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| NameofScope.cs:11:18:11:26 | nameof(...) | [My(...)] | T |
2+
| NameofScope.cs:14:26:14:34 | nameof(...) | [return: My(...)] | y |
3+
| NameofScope.cs:17:35:17:43 | nameof(...) | [My(...)] | z |
4+
| NameofScope.cs:19:38:19:46 | nameof(...) | [My(...)] | S |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import csharp
2+
3+
query predicate nameof(NameOfExpr e, string parent, string v) {
4+
e.getFile().getStem() = "NameofScope" and
5+
e.getParent().toString() = parent and
6+
v = e.getValue()
7+
}

0 commit comments

Comments
 (0)