Skip to content

Commit 42aaae7

Browse files
committed
C#: Add test case for property calls and update test expected for other files.
1 parent 49a435c commit 42aaae7

5 files changed

Lines changed: 90 additions & 0 deletions

File tree

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,50 @@ properties.cs:
246246
# 133| 0: [FieldAccess] access to field Prop.field
247247
# 133| 1: [ParameterAccess] access to parameter value
248248
# 130| 7: [Field] Prop.field
249+
# 137| 11: [RefStruct] S
250+
# 139| 6: [Field] x
251+
# 139| -1: [TypeMention] int
252+
# 141| 7: [InstanceConstructor] S
253+
#-----| 2: (Parameters)
254+
# 141| 0: [Parameter] v
255+
# 141| -1: [TypeMention] int
256+
# 142| 4: [BlockStmt] {...}
257+
# 143| 0: [ExprStmt] ...;
258+
# 143| 0: [AssignExpr] ... = ...
259+
# 143| 0: [FieldAccess] access to field x
260+
# 143| 1: [RefExpr] ref ...
261+
# 143| 0: [ParameterAccess] access to parameter v
262+
# 146| 8: [Property] Prop
263+
# 146| -1: [TypeMention] int
264+
# 148| 3: [Getter] get_Prop
265+
# 148| 4: [BlockStmt] {...}
266+
# 148| 0: [ReturnStmt] return ...;
267+
# 148| 0: [RefExpr] ref ...
268+
# 148| 0: [FieldAccess] access to field x
269+
# 152| 12: [Class] TestRefReturns
270+
# 154| 6: [Method] M
271+
# 154| -1: [TypeMention] Void
272+
# 155| 4: [BlockStmt] {...}
273+
# 156| 0: [LocalVariableDeclStmt] ... ...;
274+
# 156| 0: [LocalVariableDeclAndInitExpr] Int32 a = ...
275+
# 156| -1: [TypeMention] int
276+
# 156| 0: [LocalVariableAccess] access to local variable a
277+
# 156| 1: [IntLiteral] 0
278+
# 158| 1: [LocalVariableDeclStmt] ... ...;
279+
# 158| 0: [LocalVariableDeclAndInitExpr] S s = ...
280+
# 158| -1: [TypeMention] S
281+
# 158| 0: [LocalVariableAccess] access to local variable s
282+
# 158| 1: [ObjectCreation] object creation of type S
283+
# 158| -1: [TypeMention] S
284+
# 158| 0: [LocalVariableAccess] access to local variable a
285+
# 159| 2: [ExprStmt] ...;
286+
# 159| 0: [AssignExpr] ... = ...
287+
# 159| 0: [PropertyCall] access to property Prop
288+
# 159| -1: [LocalVariableAccess] access to local variable s
289+
# 159| 1: [IntLiteral] 1
290+
# 160| 3: [LocalVariableDeclStmt] ... ...;
291+
# 160| 0: [LocalVariableDeclAndInitExpr] Int32 x = ...
292+
# 160| -1: [TypeMention] int
293+
# 160| 0: [LocalVariableAccess] access to local variable x
294+
# 160| 1: [PropertyCall] access to property Prop
295+
# 160| -1: [LocalVariableAccess] access to local variable s
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| Prop.field |
22
| caption |
33
| next |
4+
| x |
45
| y |
56
| z |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| properties.cs:12:23:12:29 | Caption | properties.cs:29:13:29:28 | access to property Caption | properties.cs:17:13:17:15 | set_Caption |
2+
| properties.cs:12:23:12:29 | Caption | properties.cs:30:24:30:39 | access to property Caption | properties.cs:15:13:15:15 | get_Caption |
3+
| properties.cs:57:20:57:20 | X | properties.cs:61:13:61:13 | access to property X | properties.cs:57:37:57:39 | set_X |
4+
| properties.cs:58:20:58:20 | Y | properties.cs:62:13:62:13 | access to property Y | properties.cs:58:37:58:39 | set_Y |
5+
| properties.cs:70:28:70:28 | X | properties.cs:82:46:82:51 | access to property X | properties.cs:70:32:70:34 | get_X |
6+
| properties.cs:71:28:71:28 | Y | properties.cs:83:39:83:44 | access to property Y | properties.cs:74:13:74:15 | set_Y |
7+
| properties.cs:146:24:146:27 | Prop | properties.cs:160:21:160:26 | access to property Prop | properties.cs:148:13:148:15 | get_Prop |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import csharp
2+
3+
from PropertyCall pc, Property p, Accessor target
4+
where
5+
pc.getProperty() = p and
6+
pc.getTarget() = target and
7+
p.fromSource()
8+
select p, pc, target

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,31 @@ public object Prop
133133
set { field = value; }
134134
}
135135
}
136+
137+
public ref struct S
138+
{
139+
private ref int x;
140+
141+
public S(ref int v)
142+
{
143+
x = ref v;
144+
}
145+
146+
public ref int Prop
147+
{
148+
get { return ref x; }
149+
}
150+
}
151+
152+
public class TestRefReturns
153+
{
154+
public void M()
155+
{
156+
int a = 0;
157+
158+
S s = new S(ref a);
159+
s.Prop = 1;
160+
var x = s.Prop;
161+
}
162+
}
136163
}

0 commit comments

Comments
 (0)