Skip to content

Commit 44372f4

Browse files
committed
C#: Fix attribute argument extraction when default argument value is present
1 parent 6d95ad3 commit 44372f4

File tree

5 files changed

+175
-129
lines changed

5 files changed

+175
-129
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Attribute.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,18 @@ public override void Populate(TextWriter trapFile)
6666

6767
private void ExtractArguments(TextWriter trapFile)
6868
{
69+
var ctorArguments = attributeSyntax?.ArgumentList?.Arguments.Where(a => a.NameEquals == null).ToList();
70+
6971
var childIndex = 0;
7072
foreach (var constructorArgument in symbol.ConstructorArguments)
7173
{
74+
var argSyntax = ctorArguments?.Count > childIndex
75+
? ctorArguments[childIndex]
76+
: null;
77+
7278
CreateExpressionFromArgument(
7379
constructorArgument,
74-
attributeSyntax?.ArgumentList.Arguments[childIndex].Expression,
80+
argSyntax?.Expression,
7581
this,
7682
childIndex++);
7783
}

csharp/ql/test/library-tests/attributes/AttributeArguments.expected

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,22 @@ arguments
4747
| attributes.cs:57:6:57:16 | [My(...)] | 0 | attributes.cs:57:18:57:21 | true |
4848
| attributes.cs:57:6:57:16 | [My(...)] | 1 | attributes.cs:57:28:57:29 | "" |
4949
| attributes.cs:57:6:57:16 | [My(...)] | 2 | attributes.cs:57:36:57:36 | 0 |
50-
| attributes.cs:76:2:76:5 | [Args(...)] | 0 | attributes.cs:76:7:76:8 | 42 |
51-
| attributes.cs:76:2:76:5 | [Args(...)] | 1 | attributes.cs:76:11:76:14 | null |
52-
| attributes.cs:76:2:76:5 | [Args(...)] | 2 | attributes.cs:76:17:76:25 | typeof(...) |
53-
| attributes.cs:76:2:76:5 | [Args(...)] | 3 | attributes.cs:76:28:76:30 | access to constant A |
54-
| attributes.cs:76:2:76:5 | [Args(...)] | 4 | attributes.cs:76:33:76:53 | array creation of type Int32[] |
55-
| attributes.cs:76:2:76:5 | [Args(...)] | 5 | attributes.cs:76:63:76:93 | array creation of type Object[] |
56-
| attributes.cs:79:6:79:9 | [Args(...)] | 0 | attributes.cs:79:11:79:16 | ... + ... |
57-
| attributes.cs:79:6:79:9 | [Args(...)] | 1 | attributes.cs:79:19:79:39 | array creation of type Int32[] |
58-
| attributes.cs:79:6:79:9 | [Args(...)] | 2 | attributes.cs:79:42:79:45 | null |
59-
| attributes.cs:79:6:79:9 | [Args(...)] | 3 | attributes.cs:79:48:79:52 | (...) ... |
60-
| attributes.cs:79:6:79:9 | [Args(...)] | 4 | attributes.cs:79:55:79:58 | null |
61-
| attributes.cs:79:6:79:9 | [Args(...)] | 5 | attributes.cs:79:68:79:98 | array creation of type Object[] |
50+
| attributes.cs:58:6:58:8 | [My2(...)] | 0 | attributes.cs:58:10:58:13 | true |
51+
| attributes.cs:58:6:58:8 | [My2(...)] | 1 | attributes.cs:58:16:58:20 | false |
52+
| attributes.cs:58:6:58:8 | [My2(...)] | 2 | attributes.cs:58:6:58:8 | 12 |
53+
| attributes.cs:58:6:58:8 | [My2(...)] | 3 | attributes.cs:58:27:58:28 | 42 |
54+
| attributes.cs:77:2:77:5 | [Args(...)] | 0 | attributes.cs:77:7:77:8 | 42 |
55+
| attributes.cs:77:2:77:5 | [Args(...)] | 1 | attributes.cs:77:11:77:14 | null |
56+
| attributes.cs:77:2:77:5 | [Args(...)] | 2 | attributes.cs:77:17:77:25 | typeof(...) |
57+
| attributes.cs:77:2:77:5 | [Args(...)] | 3 | attributes.cs:77:28:77:30 | access to constant A |
58+
| attributes.cs:77:2:77:5 | [Args(...)] | 4 | attributes.cs:77:33:77:53 | array creation of type Int32[] |
59+
| attributes.cs:77:2:77:5 | [Args(...)] | 5 | attributes.cs:77:63:77:93 | array creation of type Object[] |
60+
| attributes.cs:80:6:80:9 | [Args(...)] | 0 | attributes.cs:80:11:80:16 | ... + ... |
61+
| attributes.cs:80:6:80:9 | [Args(...)] | 1 | attributes.cs:80:19:80:39 | array creation of type Int32[] |
62+
| attributes.cs:80:6:80:9 | [Args(...)] | 2 | attributes.cs:80:42:80:45 | null |
63+
| attributes.cs:80:6:80:9 | [Args(...)] | 3 | attributes.cs:80:48:80:52 | (...) ... |
64+
| attributes.cs:80:6:80:9 | [Args(...)] | 4 | attributes.cs:80:55:80:58 | null |
65+
| attributes.cs:80:6:80:9 | [Args(...)] | 5 | attributes.cs:80:68:80:98 | array creation of type Object[] |
6266
constructorArguments
6367
| Assembly1.dll:0:0:0:0 | [Custom(...)] | 0 | Assembly1.dll:0:0:0:0 | 1 |
6468
| Assembly1.dll:0:0:0:0 | [Custom(...)] | 0 | Assembly1.dll:0:0:0:0 | 3 |
@@ -101,16 +105,19 @@ constructorArguments
101105
| attributes.cs:46:6:46:16 | [Conditional(...)] | 0 | attributes.cs:46:18:46:25 | "DEBUG2" |
102106
| attributes.cs:54:6:54:16 | [My(...)] | 0 | attributes.cs:54:18:54:22 | false |
103107
| attributes.cs:57:6:57:16 | [My(...)] | 0 | attributes.cs:57:18:57:21 | true |
104-
| attributes.cs:76:2:76:5 | [Args(...)] | 0 | attributes.cs:76:7:76:8 | 42 |
105-
| attributes.cs:76:2:76:5 | [Args(...)] | 1 | attributes.cs:76:11:76:14 | null |
106-
| attributes.cs:76:2:76:5 | [Args(...)] | 2 | attributes.cs:76:17:76:25 | typeof(...) |
107-
| attributes.cs:76:2:76:5 | [Args(...)] | 3 | attributes.cs:76:28:76:30 | access to constant A |
108-
| attributes.cs:76:2:76:5 | [Args(...)] | 4 | attributes.cs:76:33:76:53 | array creation of type Int32[] |
109-
| attributes.cs:79:6:79:9 | [Args(...)] | 0 | attributes.cs:79:11:79:16 | ... + ... |
110-
| attributes.cs:79:6:79:9 | [Args(...)] | 1 | attributes.cs:79:19:79:39 | array creation of type Int32[] |
111-
| attributes.cs:79:6:79:9 | [Args(...)] | 2 | attributes.cs:79:42:79:45 | null |
112-
| attributes.cs:79:6:79:9 | [Args(...)] | 3 | attributes.cs:79:48:79:52 | (...) ... |
113-
| attributes.cs:79:6:79:9 | [Args(...)] | 4 | attributes.cs:79:55:79:58 | null |
108+
| attributes.cs:58:6:58:8 | [My2(...)] | 0 | attributes.cs:58:10:58:13 | true |
109+
| attributes.cs:58:6:58:8 | [My2(...)] | 1 | attributes.cs:58:16:58:20 | false |
110+
| attributes.cs:58:6:58:8 | [My2(...)] | 2 | attributes.cs:58:6:58:8 | 12 |
111+
| attributes.cs:77:2:77:5 | [Args(...)] | 0 | attributes.cs:77:7:77:8 | 42 |
112+
| attributes.cs:77:2:77:5 | [Args(...)] | 1 | attributes.cs:77:11:77:14 | null |
113+
| attributes.cs:77:2:77:5 | [Args(...)] | 2 | attributes.cs:77:17:77:25 | typeof(...) |
114+
| attributes.cs:77:2:77:5 | [Args(...)] | 3 | attributes.cs:77:28:77:30 | access to constant A |
115+
| attributes.cs:77:2:77:5 | [Args(...)] | 4 | attributes.cs:77:33:77:53 | array creation of type Int32[] |
116+
| attributes.cs:80:6:80:9 | [Args(...)] | 0 | attributes.cs:80:11:80:16 | ... + ... |
117+
| attributes.cs:80:6:80:9 | [Args(...)] | 1 | attributes.cs:80:19:80:39 | array creation of type Int32[] |
118+
| attributes.cs:80:6:80:9 | [Args(...)] | 2 | attributes.cs:80:42:80:45 | null |
119+
| attributes.cs:80:6:80:9 | [Args(...)] | 3 | attributes.cs:80:48:80:52 | (...) ... |
120+
| attributes.cs:80:6:80:9 | [Args(...)] | 4 | attributes.cs:80:55:80:58 | null |
114121
namedArguments
115122
| Assembly1.dll:0:0:0:0 | [Custom(...)] | Prop2 | Assembly1.dll:0:0:0:0 | array creation of type Object[] |
116123
| Assembly1.dll:0:0:0:0 | [Custom(...)] | Prop2 | Assembly1.dll:0:0:0:0 | array creation of type Object[] |
@@ -119,5 +126,6 @@ namedArguments
119126
| attributes.cs:41:10:41:13 | [Args(...)] | Prop | attributes.cs:41:90:41:120 | array creation of type Object[] |
120127
| attributes.cs:57:6:57:16 | [My(...)] | x | attributes.cs:57:36:57:36 | 0 |
121128
| attributes.cs:57:6:57:16 | [My(...)] | y | attributes.cs:57:28:57:29 | "" |
122-
| attributes.cs:76:2:76:5 | [Args(...)] | Prop | attributes.cs:76:63:76:93 | array creation of type Object[] |
123-
| attributes.cs:79:6:79:9 | [Args(...)] | Prop | attributes.cs:79:68:79:98 | array creation of type Object[] |
129+
| attributes.cs:58:6:58:8 | [My2(...)] | X | attributes.cs:58:27:58:28 | 42 |
130+
| attributes.cs:77:2:77:5 | [Args(...)] | Prop | attributes.cs:77:63:77:93 | array creation of type Object[] |
131+
| attributes.cs:80:6:80:9 | [Args(...)] | Prop | attributes.cs:80:68:80:98 | array creation of type Object[] |

csharp/ql/test/library-tests/attributes/AttributeElements.expected

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
| attributes.cs:47:17:47:19 | foo | attributes.cs:46:6:46:16 | [Conditional(...)] | System.Diagnostics.ConditionalAttribute |
1414
| attributes.cs:52:23:52:23 | x | attributes.cs:52:14:52:16 | [Foo(...)] | Foo |
1515
| attributes.cs:55:10:55:11 | M1 | attributes.cs:54:6:54:16 | [My(...)] | MyAttribute |
16-
| attributes.cs:58:10:58:11 | M2 | attributes.cs:57:6:57:16 | [My(...)] | MyAttribute |
17-
| attributes.cs:77:14:77:14 | X | attributes.cs:76:2:76:5 | [Args(...)] | ArgsAttribute |
18-
| attributes.cs:81:9:81:18 | SomeMethod | attributes.cs:79:6:79:9 | [Args(...)] | ArgsAttribute |
16+
| attributes.cs:59:10:59:11 | M2 | attributes.cs:57:6:57:16 | [My(...)] | MyAttribute |
17+
| attributes.cs:59:10:59:11 | M2 | attributes.cs:58:6:58:8 | [My2(...)] | My2Attribute |
18+
| attributes.cs:78:14:78:14 | X | attributes.cs:77:2:77:5 | [Args(...)] | ArgsAttribute |
19+
| attributes.cs:82:9:82:18 | SomeMethod | attributes.cs:80:6:80:9 | [Args(...)] | ArgsAttribute |
1920
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:10:12:10:24 | [AssemblyTitle(...)] | System.Reflection.AssemblyTitleAttribute |
2021
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:11:12:11:30 | [AssemblyDescription(...)] | System.Reflection.AssemblyDescriptionAttribute |
2122
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:12:12:12:32 | [AssemblyConfiguration(...)] | System.Reflection.AssemblyConfigurationAttribute |

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

Lines changed: 125 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -130,118 +130,142 @@ attributes.cs:
130130
# 54| -1: [TypeMention] MyAttribute
131131
# 54| 0: [BoolLiteral] false
132132
# 55| 4: [BlockStmt] {...}
133-
# 58| 7: [Method] M2
134-
# 58| -1: [TypeMention] Void
133+
# 59| 7: [Method] M2
134+
# 59| -1: [TypeMention] Void
135135
#-----| 0: (Attributes)
136136
# 57| 1: [Attribute] [My(...)]
137137
# 57| -1: [TypeMention] MyAttribute
138138
# 57| 0: [BoolLiteral] true
139139
# 57| 1: [StringLiteral] ""
140140
# 57| 2: [IntLiteral] 0
141-
# 58| 4: [BlockStmt] {...}
142-
# 61| [Class] MyAttribute
141+
# 58| 2: [Attribute] [My2(...)]
142+
# 58| -1: [TypeMention] My2Attribute
143+
# 58| 0: [BoolLiteral] true
144+
# 58| 1: [BoolLiteral] false
145+
# 58| 3: [IntLiteral] 42
146+
# 59| 4: [BlockStmt] {...}
147+
# 62| [Class] MyAttribute
143148
#-----| 3: (Base types)
144-
# 61| 0: [TypeMention] Attribute
145-
# 63| 4: [Field] x
146-
# 63| -1: [TypeMention] int
147-
# 64| 5: [IndexerProperty] y
148-
# 64| -1: [TypeMention] string
149-
# 64| 3: [Getter] get_y
150-
# 64| 4: [Setter] set_y
149+
# 62| 0: [TypeMention] Attribute
150+
# 64| 4: [Field] x
151+
# 64| -1: [TypeMention] int
152+
# 65| 5: [IndexerProperty] y
153+
# 65| -1: [TypeMention] string
154+
# 65| 3: [Getter] get_y
155+
# 65| 4: [Setter] set_y
151156
#-----| 2: (Parameters)
152-
# 64| 0: [Parameter] value
153-
# 65| 6: [InstanceConstructor] MyAttribute
157+
# 65| 0: [Parameter] value
158+
# 66| 6: [InstanceConstructor] MyAttribute
154159
#-----| 2: (Parameters)
155-
# 65| 0: [Parameter] b
156-
# 65| -1: [TypeMention] bool
157-
# 65| 4: [BlockStmt] {...}
158-
# 68| [Enum] E
159-
# 68| 5: [Field] A
160-
# 68| 1: [AssignExpr] ... = ...
161-
# 68| 0: [MemberConstantAccess] access to constant A
162-
# 68| 1: [IntLiteral] 42
163-
# 70| [Class] ArgsAttribute
160+
# 66| 0: [Parameter] b
161+
# 66| -1: [TypeMention] bool
162+
# 66| 4: [BlockStmt] {...}
163+
# 69| [Enum] E
164+
# 69| 5: [Field] A
165+
# 69| 1: [AssignExpr] ... = ...
166+
# 69| 0: [MemberConstantAccess] access to constant A
167+
# 69| 1: [IntLiteral] 42
168+
# 71| [Class] ArgsAttribute
164169
#-----| 3: (Base types)
165-
# 70| 0: [TypeMention] Attribute
166-
# 72| 4: [Property] Prop
167-
# 72| -1: [TypeMention] Object[]
168-
# 72| 1: [TypeMention] object
169-
# 72| 3: [Getter] get_Prop
170-
# 72| 4: [Setter] set_Prop
170+
# 71| 0: [TypeMention] Attribute
171+
# 73| 4: [Property] Prop
172+
# 73| -1: [TypeMention] Object[]
173+
# 73| 1: [TypeMention] object
174+
# 73| 3: [Getter] get_Prop
175+
# 73| 4: [Setter] set_Prop
171176
#-----| 2: (Parameters)
172-
# 72| 0: [Parameter] value
173-
# 73| 5: [InstanceConstructor] ArgsAttribute
177+
# 73| 0: [Parameter] value
178+
# 74| 5: [InstanceConstructor] ArgsAttribute
174179
#-----| 2: (Parameters)
175-
# 73| 0: [Parameter] i
176-
# 73| -1: [TypeMention] int
177-
# 73| 1: [Parameter] o
178-
# 73| -1: [TypeMention] object
179-
# 73| 2: [Parameter] t
180-
# 73| -1: [TypeMention] Type
181-
# 73| 3: [Parameter] e
182-
# 73| -1: [TypeMention] E
183-
# 73| 4: [Parameter] arr
184-
# 73| -1: [TypeMention] Int32[]
185-
# 73| 1: [TypeMention] int
186-
# 73| 4: [BlockStmt] {...}
187-
# 77| [Class] X
180+
# 74| 0: [Parameter] i
181+
# 74| -1: [TypeMention] int
182+
# 74| 1: [Parameter] o
183+
# 74| -1: [TypeMention] object
184+
# 74| 2: [Parameter] t
185+
# 74| -1: [TypeMention] Type
186+
# 74| 3: [Parameter] e
187+
# 74| -1: [TypeMention] E
188+
# 74| 4: [Parameter] arr
189+
# 74| -1: [TypeMention] Int32[]
190+
# 74| 1: [TypeMention] int
191+
# 74| 4: [BlockStmt] {...}
192+
# 78| [Class] X
188193
#-----| 0: (Attributes)
189-
# 76| 1: [Attribute] [Args(...)]
190-
# 76| -1: [TypeMention] ArgsAttribute
191-
# 76| 0: [IntLiteral] 42
192-
# 76| 1: [NullLiteral] null
193-
# 76| 2: [TypeofExpr] typeof(...)
194-
# 76| 0: [TypeAccess] access to type X
195-
# 76| 0: [TypeMention] X
196-
# 76| 3: [MemberConstantAccess] access to constant A
197-
# 76| -1: [TypeAccess] access to type E
198-
# 76| 0: [TypeMention] E
199-
# 76| 4: [ArrayCreation] array creation of type Int32[]
200-
# 76| -2: [TypeMention] Int32[]
201-
# 76| 1: [TypeMention] int
202-
# 76| -1: [ArrayInitializer] { ..., ... }
203-
# 76| 0: [IntLiteral] 1
204-
# 76| 1: [IntLiteral] 2
205-
# 76| 2: [IntLiteral] 3
206-
# 76| 5: [ArrayCreation] array creation of type Object[]
207-
# 76| -2: [TypeMention] Object[]
208-
# 76| 1: [TypeMention] object
209-
# 76| -1: [ArrayInitializer] { ..., ... }
210-
# 76| 0: [CastExpr] (...) ...
211-
# 76| 1: [IntLiteral] 1
212-
# 76| 1: [TypeofExpr] typeof(...)
213-
# 76| 0: [TypeAccess] access to type Int32
214-
# 76| 0: [TypeMention] int
215-
# 81| 5: [Method] SomeMethod
216-
# 81| -1: [TypeMention] int
194+
# 77| 1: [Attribute] [Args(...)]
195+
# 77| -1: [TypeMention] ArgsAttribute
196+
# 77| 0: [IntLiteral] 42
197+
# 77| 1: [NullLiteral] null
198+
# 77| 2: [TypeofExpr] typeof(...)
199+
# 77| 0: [TypeAccess] access to type X
200+
# 77| 0: [TypeMention] X
201+
# 77| 3: [MemberConstantAccess] access to constant A
202+
# 77| -1: [TypeAccess] access to type E
203+
# 77| 0: [TypeMention] E
204+
# 77| 4: [ArrayCreation] array creation of type Int32[]
205+
# 77| -2: [TypeMention] Int32[]
206+
# 77| 1: [TypeMention] int
207+
# 77| -1: [ArrayInitializer] { ..., ... }
208+
# 77| 0: [IntLiteral] 1
209+
# 77| 1: [IntLiteral] 2
210+
# 77| 2: [IntLiteral] 3
211+
# 77| 5: [ArrayCreation] array creation of type Object[]
212+
# 77| -2: [TypeMention] Object[]
213+
# 77| 1: [TypeMention] object
214+
# 77| -1: [ArrayInitializer] { ..., ... }
215+
# 77| 0: [CastExpr] (...) ...
216+
# 77| 1: [IntLiteral] 1
217+
# 77| 1: [TypeofExpr] typeof(...)
218+
# 77| 0: [TypeAccess] access to type Int32
219+
# 77| 0: [TypeMention] int
220+
# 82| 5: [Method] SomeMethod
221+
# 82| -1: [TypeMention] int
217222
#-----| 0: (Attributes)
218-
# 79| 1: [Attribute] [Args(...)]
219-
# 79| -1: [TypeMention] ArgsAttribute
220-
# 79| 0: [AddExpr] ... + ...
221-
# 79| 0: [IntLiteral] 42
222-
# 79| 1: [IntLiteral] 0
223-
# 79| 1: [ArrayCreation] array creation of type Int32[]
224-
# 79| -2: [TypeMention] Int32[]
225-
# 79| 1: [TypeMention] int
226-
# 79| -1: [ArrayInitializer] { ..., ... }
227-
# 79| 0: [IntLiteral] 1
228-
# 79| 1: [IntLiteral] 2
229-
# 79| 2: [IntLiteral] 3
230-
# 79| 2: [NullLiteral] null
231-
# 79| 3: [CastExpr] (...) ...
232-
# 79| 0: [TypeAccess] access to type E
233-
# 79| 0: [TypeMention] E
234-
# 79| 1: [IntLiteral] 12
235-
# 79| 4: [NullLiteral] null
236-
# 79| 5: [ArrayCreation] array creation of type Object[]
237-
# 79| -2: [TypeMention] Object[]
238-
# 79| 1: [TypeMention] object
239-
# 79| -1: [ArrayInitializer] { ..., ... }
240-
# 79| 0: [CastExpr] (...) ...
241-
# 79| 1: [IntLiteral] 1
242-
# 79| 1: [TypeofExpr] typeof(...)
243-
# 79| 0: [TypeAccess] access to type Int32
244-
# 79| 0: [TypeMention] int
245-
# 81| 4: [BlockStmt] {...}
246-
# 81| 0: [ReturnStmt] return ...;
247-
# 81| 0: [IntLiteral] 1
223+
# 80| 1: [Attribute] [Args(...)]
224+
# 80| -1: [TypeMention] ArgsAttribute
225+
# 80| 0: [AddExpr] ... + ...
226+
# 80| 0: [IntLiteral] 42
227+
# 80| 1: [IntLiteral] 0
228+
# 80| 1: [ArrayCreation] array creation of type Int32[]
229+
# 80| -2: [TypeMention] Int32[]
230+
# 80| 1: [TypeMention] int
231+
# 80| -1: [ArrayInitializer] { ..., ... }
232+
# 80| 0: [IntLiteral] 1
233+
# 80| 1: [IntLiteral] 2
234+
# 80| 2: [IntLiteral] 3
235+
# 80| 2: [NullLiteral] null
236+
# 80| 3: [CastExpr] (...) ...
237+
# 80| 0: [TypeAccess] access to type E
238+
# 80| 0: [TypeMention] E
239+
# 80| 1: [IntLiteral] 12
240+
# 80| 4: [NullLiteral] null
241+
# 80| 5: [ArrayCreation] array creation of type Object[]
242+
# 80| -2: [TypeMention] Object[]
243+
# 80| 1: [TypeMention] object
244+
# 80| -1: [ArrayInitializer] { ..., ... }
245+
# 80| 0: [CastExpr] (...) ...
246+
# 80| 1: [IntLiteral] 1
247+
# 80| 1: [TypeofExpr] typeof(...)
248+
# 80| 0: [TypeAccess] access to type Int32
249+
# 80| 0: [TypeMention] int
250+
# 82| 4: [BlockStmt] {...}
251+
# 82| 0: [ReturnStmt] return ...;
252+
# 82| 0: [IntLiteral] 1
253+
# 85| [Class] My2Attribute
254+
#-----| 3: (Base types)
255+
# 85| 0: [TypeMention] Attribute
256+
# 87| 4: [Property] X
257+
# 87| -1: [TypeMention] int
258+
# 87| 3: [Getter] get_X
259+
# 87| 4: [Setter] set_X
260+
#-----| 2: (Parameters)
261+
# 87| 0: [Parameter] value
262+
# 88| 5: [InstanceConstructor] My2Attribute
263+
#-----| 2: (Parameters)
264+
# 88| 0: [Parameter] a
265+
# 88| -1: [TypeMention] bool
266+
# 88| 1: [Parameter] b
267+
# 88| -1: [TypeMention] bool
268+
# 88| 2: [Parameter] i
269+
# 88| -1: [TypeMention] int
270+
# 88| 1: [IntLiteral] 12
271+
# 88| 4: [BlockStmt] {...}

csharp/ql/test/library-tests/attributes/attributes.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Bar
5555
void M1() { }
5656

5757
[MyAttribute(true, y = "", x = 0)]
58+
[My2(true, false, X = 42)]
5859
void M2() { }
5960
}
6061

@@ -80,3 +81,9 @@ public class X
8081
[return: Args(42 + 0, new int[] { 1, 2, 3 }, null, (E)12, null, Prop = new object[] { 1, typeof(int) })]
8182
int SomeMethod() { return 1; }
8283
}
84+
85+
class My2Attribute : Attribute
86+
{
87+
public int X { get; set; }
88+
public My2Attribute(bool a, bool b, int i = 12) { }
89+
}

0 commit comments

Comments
 (0)