Skip to content

Commit 5e16bb4

Browse files
committed
C#: Add a tests for MaybeNullExpr.
1 parent d6f9756 commit 5e16bb4

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
3+
public class C
4+
{
5+
string Prop { get; set; }
6+
7+
void M(object o, bool b)
8+
{
9+
// Conditional expr might be null.
10+
var conditionalExpr = b ? new object() : null;
11+
12+
// Null-coalescing expr might be null as the right operand is null.
13+
var nullCoalescing = o ?? null;
14+
15+
// Cast might be null.
16+
var c = o as C;
17+
18+
// Conditional access might be null as the qualifier might be null.
19+
var s1 = (o as C)?.Prop;
20+
}
21+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| MaybeNullExpr.cs:10:31:10:53 | ... ? ... : ... |
2+
| MaybeNullExpr.cs:10:50:10:53 | null |
3+
| MaybeNullExpr.cs:13:30:13:38 | ... ?? ... |
4+
| MaybeNullExpr.cs:13:35:13:38 | null |
5+
| MaybeNullExpr.cs:16:17:16:22 | ... as ... |
6+
| MaybeNullExpr.cs:19:19:19:24 | ... as ... |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import csharp
2+
import semmle.code.csharp.dataflow.Nullness
3+
4+
from MaybeNullExpr e
5+
where e.fromSource()
6+
select e
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
semmle-extractor-options: /nostdlib /noconfig
2+
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj

0 commit comments

Comments
 (0)