Skip to content

Commit 0355ea8

Browse files
committed
C#: Add some synthetic library extensions methods and tests for cs/dereferenced-value-is-always-null.
1 parent 76c12a5 commit 0355ea8

File tree

6 files changed

+647
-602
lines changed

6 files changed

+647
-602
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Library;
2+
3+
public class F
4+
{
5+
public void M1()
6+
{
7+
object o = null;
8+
o.Accept(); // $ Alert[cs/dereferenced-value-is-always-null]
9+
}
10+
11+
public void M2()
12+
{
13+
object? o = null;
14+
o.AcceptNullable();
15+
}
16+
}

csharp/ql/test/query-tests/Nullness/Implications.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,10 @@
13051305
| E.cs:442:13:442:29 | ... is ... | true | E.cs:442:13:442:13 | access to parameter s | non-null |
13061306
| E.cs:447:13:447:25 | ... is ... | true | E.cs:447:13:447:13 | access to parameter s | non-null |
13071307
| E.cs:452:13:452:23 | ... is ... | true | E.cs:452:13:452:13 | access to parameter s | non-null |
1308+
| F.cs:8:9:8:9 | access to local variable o | non-null | F.cs:7:20:7:23 | null | non-null |
1309+
| F.cs:8:9:8:9 | access to local variable o | null | F.cs:7:20:7:23 | null | null |
1310+
| F.cs:14:9:14:9 | access to local variable o | non-null | F.cs:13:21:13:24 | null | non-null |
1311+
| F.cs:14:9:14:9 | access to local variable o | null | F.cs:13:21:13:24 | null | null |
13081312
| Forwarding.cs:9:13:9:30 | !... | false | Forwarding.cs:9:14:9:30 | call to method IsNullOrEmpty | true |
13091313
| Forwarding.cs:9:13:9:30 | !... | true | Forwarding.cs:9:14:9:30 | call to method IsNullOrEmpty | false |
13101314
| Forwarding.cs:9:14:9:14 | access to local variable s | empty | Forwarding.cs:7:20:7:23 | null | empty |

csharp/ql/test/query-tests/Nullness/NullAlways.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#select
12
| A.cs:8:15:8:32 | access to local variable synchronizedAlways | Variable $@ is always null at this dereference. | A.cs:7:16:7:33 | synchronizedAlways | synchronizedAlways |
23
| A.cs:17:9:17:17 | access to local variable arrayNull | Variable $@ is always null at this dereference. | A.cs:16:15:16:23 | arrayNull | arrayNull |
34
| A.cs:31:27:31:37 | access to local variable arrayAccess | Variable $@ is always null at this dereference. | A.cs:26:15:26:25 | arrayAccess | arrayAccess |
@@ -38,6 +39,10 @@
3839
| E.cs:331:9:331:9 | access to local variable x | Variable $@ is always null at this dereference. | E.cs:330:13:330:13 | x | x |
3940
| E.cs:405:16:405:16 | access to local variable i | Variable $@ is always null at this dereference. | E.cs:403:14:403:14 | i | i |
4041
| E.cs:439:13:439:13 | access to parameter s | Variable $@ is always null at this dereference. | E.cs:435:29:435:29 | s | s |
42+
| F.cs:8:9:8:9 | access to local variable o | Variable $@ is always null at this dereference. | F.cs:7:16:7:16 | o | o |
43+
| F.cs:14:9:14:9 | access to local variable o | Variable $@ is always null at this dereference. | F.cs:13:17:13:17 | o | o |
4144
| Forwarding.cs:36:31:36:31 | access to local variable s | Variable $@ is always null at this dereference. | Forwarding.cs:7:16:7:16 | s | s |
4245
| Forwarding.cs:40:27:40:27 | access to local variable s | Variable $@ is always null at this dereference. | Forwarding.cs:7:16:7:16 | s | s |
4346
| NullAlwaysBad.cs:9:30:9:30 | access to parameter s | Variable $@ is always null at this dereference. | NullAlwaysBad.cs:7:29:7:29 | s | s |
47+
testFailures
48+
| F.cs:14:9:14:9 | Variable $@ is always null at this dereference. | Unexpected result: Alert |

0 commit comments

Comments
 (0)