Skip to content

Commit 4748d2c

Browse files
committed
C# Exclude dynamic casts from useless casts check
1 parent 422c2d5 commit 4748d2c

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

csharp/ql/src/Language Abuse/UselessUpcast.ql

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,8 @@ class ExplicitUpcast extends ExplicitCast {
204204
this = any(LocalVariableDeclAndInitExpr decl | decl.isImplicitlyTyped()).getInitializer()
205205
or
206206
exists(LambdaExpr c | c.canReturn(this))
207-
}
208-
}
209-
210-
// Stop external filepaths from appearing in the results
211-
class ValueOrRefTypeLocation extends ValueOrRefType {
212-
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
213-
exists(string fullPath | super.hasLocationInfo(fullPath, sl, sc, el, ec) |
214-
if exists(this.getFile().getRelativePath())
215-
then path = fullPath
216-
else path = fullPath.regexpReplaceAll(".*/", "<external>/")
217-
)
207+
or
208+
dest instanceof DynamicType
218209
}
219210
}
220211

csharp/ql/test/query-tests/Language Abuse/UselessUpcast/UselessUpcast.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66
| UselessUpcast.cs:103:16:103:19 | (...) ... | There is no need to upcast from $@ to $@ - the conversion can be done implicitly. | UselessUpcast.cs:25:7:25:7 | C | C | UselessUpcast.cs:18:7:18:7 | B | B |
77
| UselessUpcast.cs:158:34:158:40 | (...) ... | There is no need to upcast from $@ to $@ - the conversion can be done implicitly. | UselessUpcast.cs:156:11:156:16 | SubSub | SubSub | UselessUpcast.cs:151:11:151:13 | Sub | Sub |
88
| UselessUpcast.cs:162:21:162:27 | (...) ... | There is no need to upcast from $@ to $@ - the conversion can be done implicitly. | UselessUpcast.cs:156:11:156:16 | SubSub | SubSub | UselessUpcast.cs:151:11:151:13 | Sub | Sub |
9-
| UselessUpcast.cs:170:23:170:32 | (...) ... | There is no need to upcast from $@ to $@ - the conversion can be done implicitly. | file://<external>/System.Private.CoreLib.dll:0:0:0:0 | Object | Object | file://<external>/System.Private.CoreLib.dll:0:0:0:0 | dynamic | dynamic |
109
| UselessUpcastBad.cs:9:23:9:32 | (...) ... | There is no need to upcast from $@ to $@ - the conversion can be done implicitly. | UselessUpcastBad.cs:4:11:4:13 | Sub | Sub | UselessUpcastBad.cs:3:11:3:15 | Super | Super |

0 commit comments

Comments
 (0)