Skip to content

Commit a2ac0ab

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

4 files changed

Lines changed: 92 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| indexers.cs:24:21:24:24 | Item | indexers.cs:62:22:62:29 | access to indexer | indexers.cs:26:13:26:15 | get_Item |
2+
| indexers.cs:24:21:24:24 | Item | indexers.cs:65:25:65:32 | access to indexer | indexers.cs:34:13:34:15 | set_Item |
3+
| indexers.cs:143:24:143:27 | Item | indexers.cs:157:21:157:24 | access to indexer | indexers.cs:145:13:145:15 | get_Item |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import csharp
2+
3+
from IndexerCall ic, Indexer i, Accessor target
4+
where
5+
ic.getIndexer() = i and
6+
ic.getTarget() = target and
7+
i.fromSource()
8+
select i, ic, target

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,57 @@ indexers.cs:
360360
# 130| 4: [BlockStmt] {...}
361361
# 130| 0: [ReturnStmt] return ...;
362362
# 130| 0: [IntLiteral] 0
363+
# 134| 5: [RefStruct] S
364+
# 136| 6: [Field] x
365+
# 136| -1: [TypeMention] int
366+
# 138| 7: [InstanceConstructor] S
367+
#-----| 2: (Parameters)
368+
# 138| 0: [Parameter] v
369+
# 138| -1: [TypeMention] int
370+
# 139| 4: [BlockStmt] {...}
371+
# 140| 0: [ExprStmt] ...;
372+
# 140| 0: [AssignExpr] ... = ...
373+
# 140| 0: [FieldAccess] access to field x
374+
# 140| 1: [RefExpr] ref ...
375+
# 140| 0: [ParameterAccess] access to parameter v
376+
# 143| 8: [Indexer] Item
377+
# 143| -1: [TypeMention] int
378+
#-----| 1: (Parameters)
379+
# 143| 0: [Parameter] i
380+
# 143| -1: [TypeMention] int
381+
# 145| 3: [Getter] get_Item
382+
#-----| 2: (Parameters)
383+
# 143| 0: [Parameter] i
384+
# 145| 4: [BlockStmt] {...}
385+
# 145| 0: [ReturnStmt] return ...;
386+
# 145| 0: [RefExpr] ref ...
387+
# 145| 0: [FieldAccess] access to field x
388+
# 149| 6: [Class] TestRefReturns
389+
# 151| 6: [Method] M
390+
# 151| -1: [TypeMention] Void
391+
# 152| 4: [BlockStmt] {...}
392+
# 153| 0: [LocalVariableDeclStmt] ... ...;
393+
# 153| 0: [LocalVariableDeclAndInitExpr] Int32 a = ...
394+
# 153| -1: [TypeMention] int
395+
# 153| 0: [LocalVariableAccess] access to local variable a
396+
# 153| 1: [IntLiteral] 0
397+
# 155| 1: [LocalVariableDeclStmt] ... ...;
398+
# 155| 0: [LocalVariableDeclAndInitExpr] S s = ...
399+
# 155| -1: [TypeMention] S
400+
# 155| 0: [LocalVariableAccess] access to local variable s
401+
# 155| 1: [ObjectCreation] object creation of type S
402+
# 155| -1: [TypeMention] S
403+
# 155| 0: [LocalVariableAccess] access to local variable a
404+
# 156| 2: [ExprStmt] ...;
405+
# 156| 0: [AssignExpr] ... = ...
406+
# 156| 0: [IndexerCall] access to indexer
407+
# 156| -1: [LocalVariableAccess] access to local variable s
408+
# 156| 0: [IntLiteral] 0
409+
# 156| 1: [IntLiteral] 1
410+
# 157| 3: [LocalVariableDeclStmt] ... ...;
411+
# 157| 0: [LocalVariableDeclAndInitExpr] Int32 x = ...
412+
# 157| -1: [TypeMention] int
413+
# 157| 0: [LocalVariableAccess] access to local variable x
414+
# 157| 1: [IndexerCall] access to indexer
415+
# 157| -1: [LocalVariableAccess] access to local variable s
416+
# 157| 0: [IntLiteral] 0

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,31 @@ public bool this[int index]
130130
get { return 0; }
131131
}
132132
}
133+
134+
public ref struct S
135+
{
136+
private ref int x;
137+
138+
public S(ref int v)
139+
{
140+
x = ref v;
141+
}
142+
143+
public ref int this[int i]
144+
{
145+
get { return ref x; }
146+
}
147+
}
148+
149+
public class TestRefReturns
150+
{
151+
public void M()
152+
{
153+
int a = 0;
154+
155+
S s = new S(ref a);
156+
s[0] = 1;
157+
var x = s[0];
158+
}
159+
}
133160
}

0 commit comments

Comments
 (0)