C#: Add BMN tests for cs/constant-condition.

This commit is contained in:
Michael Nebel
2025-03-07 13:20:03 +01:00
parent 431586bb70
commit 5c0fc1f75b
4 changed files with 34 additions and 0 deletions

View File

@@ -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
{
}
}
}

View File

@@ -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. |

View File

@@ -0,0 +1,2 @@
query: Bad Practices/Control-Flow/ConstantCondition.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -0,0 +1 @@
semmle-extractor-options: --standalone