Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ private predicate isMatchingConstant(PatternExpr pe, boolean value) {
value = true
or
exists(Type t, Type strippedType |
not t instanceof UnknownType and
not strippedType instanceof UnknownType and
typePatternMustHaveMatchingCompletion(pe, t, strippedType) and
not typePatternCommonSubType(t, strippedType) and
value = false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* Increase query precision for `cs/useless-assignment-to-local` and `cs/constant-condition` when *unknown* types are involved (mostly relevant for `build-mode: none` databases).
Original file line number Diff line number Diff line change
@@ -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)
{
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| 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. |
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
query: Bad Practices/Control-Flow/ConstantCondition.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
semmle-extractor-options: --standalone