Skip to content

Commit d83985a

Browse files
authored
Merge pull request #22393 from michaelnebel/csharp/useless-cast-to-self-unknown-type
C#: Harden `cs/useless-cast-to-self` with respect to unknown types.
2 parents d24ab5e + 97985c8 commit d83985a

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

csharp/ql/src/Language Abuse/UselessCastToSelf.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ where
1919
type = cast.getTargetType() and
2020
type = e.getType() and
2121
not type instanceof NullType and
22+
not type instanceof UnknownType and
2223
not e.(ImplicitDelegateCreation).getArgument() instanceof AnonymousFunctionExpr
2324
select cast, "This cast is redundant because the expression already has type " + type + "."
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: fix
3+
---
4+
* The query `cs/useless-cast-to-self` no longer reports casts when both the expression type and the cast target type are unknown, which can occur in `build-mode: none` databases.

0 commit comments

Comments
 (0)