File tree 5 files changed +26
-17
lines changed
test/query-tests/Useless Code/IntGetHashCode
5 files changed +26
-17
lines changed Original file line number Diff line number Diff line change @@ -16,5 +16,12 @@ import semmle.code.csharp.frameworks.System
16
16
from MethodCall mc , IntegralType t
17
17
where
18
18
mc .getTarget ( ) instanceof GetHashCodeMethod and
19
- t = mc .getQualifier ( ) .getType ( )
19
+ t = mc .getQualifier ( ) .getType ( ) and
20
+ (
21
+ t instanceof ByteType or
22
+ t instanceof SByteType or
23
+ t instanceof ShortType or
24
+ t instanceof UShortType or
25
+ t instanceof IntType
26
+ )
20
27
select mc , "Calling GetHashCode() on type " + t .toStringWithTypes ( ) + " is redundant."
Original file line number Diff line number Diff line change
1
+ ---
2
+ category : minorAnalysis
3
+ ---
4
+ * Increase query precision for ` cs/useless-gethashcode-call ` by not flagging calls to ` GetHashCode ` on ` uint ` , ` long ` and ` ulong ` .
Original file line number Diff line number Diff line change @@ -3,16 +3,16 @@ class IntGetHashCode
3
3
void Test ( )
4
4
{
5
5
// These are all bad:
6
+ default ( int ) . GetHashCode ( ) ; // $ Alert
7
+ default ( short ) . GetHashCode ( ) ; // $ Alert
8
+ default ( ushort ) . GetHashCode ( ) ; // $ Alert
9
+ default ( byte ) . GetHashCode ( ) ; // $ Alert
10
+ default ( sbyte ) . GetHashCode ( ) ; // $ Alert
11
+
12
+ // These are all good:
6
13
default ( uint ) . GetHashCode ( ) ;
7
- default ( int ) . GetHashCode ( ) ;
8
14
default ( long ) . GetHashCode ( ) ;
9
15
default ( ulong ) . GetHashCode ( ) ;
10
- default ( short ) . GetHashCode ( ) ;
11
- default ( ushort ) . GetHashCode ( ) ;
12
- default ( byte ) . GetHashCode ( ) ;
13
- default ( sbyte ) . GetHashCode ( ) ;
14
-
15
- // These are all good:
16
16
default ( double ) . GetHashCode ( ) ;
17
17
default ( float ) . GetHashCode ( ) ;
18
18
default ( char ) . GetHashCode ( ) ;
Original file line number Diff line number Diff line change 1
- | IntGetHashCode.cs:6:9:6:35 | call to method GetHashCode | Calling GetHashCode() on type uint is redundant. |
2
- | IntGetHashCode.cs:7:9:7:34 | call to method GetHashCode | Calling GetHashCode() on type int is redundant. |
3
- | IntGetHashCode.cs:8:9:8:35 | call to method GetHashCode | Calling GetHashCode() on type long is redundant. |
4
- | IntGetHashCode.cs:9:9:9:36 | call to method GetHashCode | Calling GetHashCode() on type ulong is redundant. |
5
- | IntGetHashCode.cs:10:9:10:36 | call to method GetHashCode | Calling GetHashCode() on type short is redundant. |
6
- | IntGetHashCode.cs:11:9:11:37 | call to method GetHashCode | Calling GetHashCode() on type ushort is redundant. |
7
- | IntGetHashCode.cs:12:9:12:35 | call to method GetHashCode | Calling GetHashCode() on type byte is redundant. |
8
- | IntGetHashCode.cs:13:9:13:36 | call to method GetHashCode | Calling GetHashCode() on type sbyte is redundant. |
1
+ | IntGetHashCode.cs:6:9:6:34 | call to method GetHashCode | Calling GetHashCode() on type int is redundant. |
2
+ | IntGetHashCode.cs:7:9:7:36 | call to method GetHashCode | Calling GetHashCode() on type short is redundant. |
3
+ | IntGetHashCode.cs:8:9:8:37 | call to method GetHashCode | Calling GetHashCode() on type ushort is redundant. |
4
+ | IntGetHashCode.cs:9:9:9:35 | call to method GetHashCode | Calling GetHashCode() on type byte is redundant. |
5
+ | IntGetHashCode.cs:10:9:10:36 | call to method GetHashCode | Calling GetHashCode() on type sbyte is redundant. |
Original file line number Diff line number Diff line change 1
- Useless code/IntGetHashCode.ql
1
+ query: Useless code/IntGetHashCode.ql
2
+ postprocess: utils/test/InlineExpectationsTestQuery.ql
You can’t perform that action at this time.
0 commit comments