mirror of
https://github.com/github/codeql.git
synced 2026-04-27 01:35:13 +02:00
C#: Add BMN tests for cs/constant-condition.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
|
||||
partial class C1
|
||||
{
|
||||
public C2 Prop { get; set; }
|
||||
}
|
||||
|
||||
class C2 { }
|
||||
|
||||
class ConstantMatching
|
||||
{
|
||||
void M1()
|
||||
{
|
||||
var c1 = new C1();
|
||||
if (c1.Prop is int) // $ Alert
|
||||
{
|
||||
}
|
||||
|
||||
// Should not be considered a constant condition as
|
||||
// we don't know anything about D.
|
||||
var d = new D();
|
||||
if (d.Prop is C2) // $ Alert
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
| ConstantCondition.cs:15:13:15:26 | ... is ... | Condition always evaluates to 'false'. |
|
||||
| ConstantCondition.cs:15:24:15:26 | access to type Int32 | Pattern never matches. |
|
||||
| ConstantCondition.cs:22:13:22:24 | ... is ... | Condition always evaluates to 'false'. |
|
||||
| ConstantCondition.cs:22:23:22:24 | access to type C2 | Pattern never matches. |
|
||||
@@ -0,0 +1,2 @@
|
||||
query: Bad Practices/Control-Flow/ConstantCondition.ql
|
||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
||||
@@ -0,0 +1 @@
|
||||
semmle-extractor-options: --standalone
|
||||
Reference in New Issue
Block a user