mirror of
https://github.com/github/codeql.git
synced 2026-02-11 20:51:06 +01:00
C#: Add a tests for MaybeNullExpr.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
public class C
|
||||
{
|
||||
string Prop { get; set; }
|
||||
|
||||
void M(object o, bool b)
|
||||
{
|
||||
// Conditional expr might be null.
|
||||
var conditionalExpr = b ? new object() : null;
|
||||
|
||||
// Null-coalescing expr might be null as the right operand is null.
|
||||
var nullCoalescing = o ?? null;
|
||||
|
||||
// Cast might be null.
|
||||
var c = o as C;
|
||||
|
||||
// Conditional access might be null as the qualifier might be null.
|
||||
var s1 = (o as C)?.Prop;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
| MaybeNullExpr.cs:10:31:10:53 | ... ? ... : ... |
|
||||
| MaybeNullExpr.cs:10:50:10:53 | null |
|
||||
| MaybeNullExpr.cs:13:30:13:38 | ... ?? ... |
|
||||
| MaybeNullExpr.cs:13:35:13:38 | null |
|
||||
| MaybeNullExpr.cs:16:17:16:22 | ... as ... |
|
||||
| MaybeNullExpr.cs:19:19:19:24 | ... as ... |
|
||||
@@ -0,0 +1,6 @@
|
||||
import csharp
|
||||
import semmle.code.csharp.dataflow.Nullness
|
||||
|
||||
from MaybeNullExpr e
|
||||
where e.fromSource()
|
||||
select e
|
||||
2
csharp/ql/test/library-tests/dataflow/nullness/options
Normal file
2
csharp/ql/test/library-tests/dataflow/nullness/options
Normal file
@@ -0,0 +1,2 @@
|
||||
semmle-extractor-options: /nostdlib /noconfig
|
||||
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj
|
||||
Reference in New Issue
Block a user