Skip to content

Commit ca23e1b

Browse files
committed
C#: Test example with ref local, unsafe context and ref struct in async and iterator methods.
1 parent f62a3ac commit ca23e1b

File tree

6 files changed

+56
-0
lines changed

6 files changed

+56
-0
lines changed

csharp/ql/test/library-tests/async/Async.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212
| async.cs:50:49:50:57 | OpenAsync | file://:0:0:0:0 | async |
1313
| async.cs:50:49:50:57 | OpenAsync | file://:0:0:0:0 | private |
1414
| async.cs:50:49:50:57 | OpenAsync | file://:0:0:0:0 | static |
15+
| async.cs:64:40:64:53 | GetObjectAsync | file://:0:0:0:0 | async |
16+
| async.cs:64:40:64:53 | GetObjectAsync | file://:0:0:0:0 | private |
17+
| async.cs:64:40:64:53 | GetObjectAsync | file://:0:0:0:0 | static |

csharp/ql/test/library-tests/async/Await.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
| 42 | async.cs:42:46:42:70 | await ... | async.cs:42:52:42:70 | call to method OpenAsync |
44
| 44 | async.cs:44:38:44:66 | await ... | async.cs:44:44:44:66 | call to method ReadToEndAsync |
55
| 52 | async.cs:52:13:52:51 | await ... | async.cs:52:19:52:51 | call to method PrintContentLengthAsync |
6+
| 73 | async.cs:73:13:73:31 | await ... | async.cs:73:19:73:31 | call to method Delay |

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,26 @@ private static async Task<StreamReader> OpenAsync(string filename)
5252
await PrintContentLengthAsync(filename);
5353
return File.OpenText(filename);
5454
}
55+
56+
private ref struct RS
57+
{
58+
public int GetZero() { return 0; }
59+
}
60+
61+
private static int one = 1;
62+
63+
// Test that we can use ref locals, ref structs and unsafe blocks in async methods.
64+
private static async Task<int> GetObjectAsync()
65+
{
66+
unsafe
67+
{
68+
// Do pointer stuff
69+
}
70+
RS rs;
71+
ref int i = ref one;
72+
var zero = rs.GetZero();
73+
await Task.Delay(i);
74+
return zero;
75+
}
5576
}
5677
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
public ref struct RS
5+
{
6+
public int GetZero() { return 0; }
7+
}
8+
9+
public class C
10+
{
11+
private int one = 1;
12+
13+
// Test that we can use unsafe context, ref locals and ref structs in iterators.
14+
public IEnumerable<int> GetObjects()
15+
{
16+
unsafe
17+
{
18+
// Do pointer stuff
19+
}
20+
ref int i = ref one;
21+
RS rs;
22+
var zero = rs.GetZero();
23+
yield return zero;
24+
}
25+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| iterators.cs:14:29:14:38 | GetObjects | iterators.cs:23:22:23:25 | access to local variable zero |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import csharp
2+
3+
from Callable c, Expr return
4+
where c.canYieldReturn(return)
5+
select c, return

0 commit comments

Comments
 (0)