Skip to content

Commit 7ff1c12

Browse files
committed
C#: Add some more tests.
1 parent 7ae2b76 commit 7ff1c12

File tree

5 files changed

+17
-0
lines changed

5 files changed

+17
-0
lines changed

csharp/ql/test/library-tests/dataflow/nullness/MaybeNullExpr.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ void M(object o, bool b)
1717

1818
// Conditional access might be null as the qualifier might be null.
1919
var s1 = (o as C)?.Prop;
20+
21+
// Conditional access might be null as the qualifier might be null.
22+
var i = o?.GetHashCode();
2023
}
2124
}

csharp/ql/test/library-tests/dataflow/nullness/maybeNullExpr.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
| MaybeNullExpr.cs:16:17:16:22 | ... as ... |
66
| MaybeNullExpr.cs:19:18:19:31 | access to property Prop |
77
| MaybeNullExpr.cs:19:19:19:24 | ... as ... |
8+
| MaybeNullExpr.cs:22:17:22:32 | call to method GetHashCode |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.ComponentModel;
3+
4+
class ConditionalAccessTest
5+
{
6+
void M1(object o)
7+
{
8+
var t = o?.GetType();
9+
Console.WriteLine(t.FullName); // $ Alert[cs/dereferenced-value-may-be-null]
10+
}
11+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
| C.cs:229:22:229:30 | ... != ... | C.cs:229:22:229:22 | access to local variable s |
5252
| C.cs:235:24:235:32 | ... == ... | C.cs:235:24:235:24 | access to local variable s |
5353
| C.cs:235:24:235:32 | ... == ... | C.cs:235:29:235:32 | null |
54+
| ConditionalAccess.cs:8:17:8:17 | access to parameter o | ConditionalAccess.cs:8:17:8:17 | access to parameter o |
5455
| D.cs:28:13:28:25 | ... != ... | D.cs:28:13:28:17 | access to parameter param |
5556
| D.cs:38:13:38:21 | ... == ... | D.cs:38:13:38:13 | access to parameter x |
5657
| D.cs:39:16:39:24 | ... == ... | D.cs:39:16:39:16 | access to parameter x |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
| C.cs:203:13:203:13 | access to local variable s | Variable $@ may be null at this access because of $@ assignment. | C.cs:185:13:185:13 | s | s | C.cs:204:13:204:20 | ... = ... | this |
77
| C.cs:223:9:223:9 | access to local variable s | Variable $@ may be null at this access because of $@ assignment. | C.cs:210:13:210:13 | s | s | C.cs:222:13:222:20 | ... = ... | this |
88
| C.cs:242:13:242:13 | access to local variable s | Variable $@ may be null at this access because of $@ assignment. | C.cs:228:16:228:16 | s | s | C.cs:240:24:240:31 | ... = ... | this |
9+
| ConditionalAccess.cs:9:27:9:27 | access to local variable t | Variable $@ may be null at this access because of $@ assignment. | ConditionalAccess.cs:8:13:8:13 | t | t | ConditionalAccess.cs:8:13:8:28 | Type t = ... | this |
910
| D.cs:23:9:23:13 | access to parameter param | Variable $@ may be null at this access because of $@ null argument. | D.cs:21:32:21:36 | param | param | D.cs:17:17:17:20 | null | this |
1011
| D.cs:32:9:32:13 | access to parameter param | Variable $@ may be null at this access as suggested by $@ null check. | D.cs:26:32:26:36 | param | param | D.cs:28:13:28:25 | ... != ... | this |
1112
| D.cs:73:13:73:14 | access to local variable o7 | Variable $@ may be null at this access because of $@ assignment. | D.cs:68:13:68:14 | o7 | o7 | D.cs:68:13:68:34 | String o7 = ... | this |

0 commit comments

Comments
 (0)