@@ -9,14 +9,14 @@ public class DeadStoreOfLocal
9
9
10
10
public int M1 ( )
11
11
{
12
- int x = M2 ( ) ; // BAD
12
+ int x = M2 ( ) ; // $ Alert
13
13
return ( x = 1 ) + x ; // GOOD
14
14
}
15
15
16
16
public int M2 ( )
17
17
{
18
18
int x = 1 ; // GOOD
19
- return x + ( x = 1 ) ; // BAD
19
+ return x + ( x = 1 ) ; // $ Alert
20
20
}
21
21
22
22
public int M3 ( )
@@ -41,19 +41,19 @@ public int M4()
41
41
42
42
public void M5 ( )
43
43
{
44
- int x = M3 ( ) ; // BAD
44
+ int x = M3 ( ) ; // $ Alert
45
45
}
46
46
47
47
public void M6 ( )
48
48
{
49
49
int x = 42 ;
50
- x += 1 ; // BAD
50
+ x += 1 ; // $ Alert
51
51
}
52
52
53
53
public void M7 ( )
54
54
{
55
55
int x = 42 ;
56
- x ++ ; // BAD
56
+ x ++ ; // $ Alert
57
57
}
58
58
59
59
public IEnumerable < string > M8 ( IEnumerable < string > source )
@@ -79,8 +79,8 @@ public IEnumerable<string> M9(IEnumerable<string> source)
79
79
80
80
public void M10 ( IEnumerable < string > source )
81
81
{
82
- foreach ( var val in source )
83
- { // BAD
82
+ foreach ( var val in source ) // $ Alert
83
+ {
84
84
}
85
85
}
86
86
}
@@ -98,10 +98,10 @@ public void F()
98
98
message = "Unsuccessful completion" ; // GOOD: Used in finally
99
99
Process ( ) ;
100
100
info2 = "Finishing" ; // GOOD: Used in exception handler
101
- extra = "Dead store here" ; // BAD: Dead store
101
+ extra = "Dead store here" ; // $ Alert Dead store
102
102
Process ( ) ;
103
103
message = "Successful completion" ; // GOOD: Used in finally
104
- info1 = "Used in handler" ; // BAD: Used in handler, but not a reachable handler
104
+ info1 = "Used in handler" ; // $ Alert Used in handler, but not a reachable handler
105
105
}
106
106
catch ( SystemException ex )
107
107
{
@@ -139,7 +139,7 @@ public void FinallyFlow2()
139
139
{
140
140
Process ( ) ;
141
141
}
142
- catch ( Exception ex ) // BAD
142
+ catch ( Exception ex ) // $ Alert
143
143
{
144
144
Console . WriteLine ( "Stage " + stage ) ;
145
145
stage = 3 ; // GOOD: Used in finally
@@ -157,7 +157,7 @@ public class OutParam
157
157
public void Test ( )
158
158
{
159
159
int x ;
160
- Fn ( out x ) ; // BAD
160
+ Fn ( out x ) ; // $ MISSING: Alert
161
161
Fn ( out _ ) ; // GOOD
162
162
}
163
163
@@ -194,7 +194,7 @@ void M1()
194
194
195
195
void M2 ( )
196
196
{
197
- var x = M6 ( ) ; // BAD [FALSE NEGATIVE]
197
+ var x = M6 ( ) ; // $ MISSING: Alert
198
198
Action a = ( ) =>
199
199
{
200
200
x = 1 ; // GOOD
@@ -208,7 +208,7 @@ void M3()
208
208
int x ;
209
209
Action a = ( ) =>
210
210
{
211
- x = 1 ; // BAD [FALSE NEGATIVE]
211
+ x = 1 ; // $ MISSING: Alert
212
212
} ;
213
213
a ( ) ;
214
214
}
@@ -230,7 +230,7 @@ void M4()
230
230
231
231
void M5 ( )
232
232
{
233
- int x = 0 ; // BAD: NOT DETECTED
233
+ int x = 0 ; // $ MISSING: Alert
234
234
Action a = ( ) =>
235
235
{
236
236
x = 1 ; // GOOD
@@ -243,22 +243,22 @@ int M6()
243
243
{
244
244
fn ( ( ) =>
245
245
{
246
- int y = M6 ( ) ; // BAD
246
+ int y = M6 ( ) ; // $ Alert
247
247
return ( y = 1 ) + y ; // GOOD
248
248
} ) ;
249
249
250
250
int captured = 0 ; // GOOD: Variable captured variable
251
251
fn ( ( ) => { return captured ; } ) ;
252
252
253
- return captured = 1 ; // BAD: NOT DETECTED
253
+ return captured = 1 ; // $ MISSING: Alert
254
254
}
255
255
256
256
void M7 ( )
257
257
{
258
258
var y = 12 ; // GOOD: Not a dead store (used in delegate)
259
259
fn ( ( ) =>
260
260
{
261
- var x = y ; // BAD: Dead store in lambda
261
+ var x = y ; // $ Alert Dead store in lambda
262
262
return 0 ;
263
263
} ) ;
264
264
}
@@ -297,8 +297,8 @@ void Test()
297
297
{ // GOOD
298
298
Console . WriteLine ( $ "int { i1 } ") ;
299
299
}
300
- else if ( o is var v1 )
301
- { // BAD
300
+ else if ( o is var v1 ) // $ Alert
301
+ {
302
302
}
303
303
304
304
switch ( o )
@@ -311,7 +311,7 @@ void Test()
311
311
case int i3 : // GOOD
312
312
Console . WriteLine ( $ "int { i3 } ") ;
313
313
break ;
314
- case var v2 : // BAD
314
+ case var v2 : // $ Alert
315
315
break ;
316
316
default :
317
317
Console . WriteLine ( "Something else" ) ;
@@ -328,7 +328,7 @@ void M()
328
328
Use ( x ) ;
329
329
Use ( b ) ;
330
330
Use ( s ) ;
331
- ( x , ( b , s ) ) = GetTuple ( ) ; // BAD: `b`
331
+ ( x , ( b , s ) ) = GetTuple ( ) ; // $ Alert on `b`
332
332
Use ( x ) ;
333
333
Use ( s ) ;
334
334
( x , ( _ , s ) ) = GetTuple ( ) ; // GOOD
@@ -369,7 +369,7 @@ string M3()
369
369
370
370
string M4 ( )
371
371
{
372
- var s = M3 ( ) ; // BAD
372
+ var s = M3 ( ) ; // $ Alert
373
373
s = "" ;
374
374
return s ;
375
375
}
@@ -395,7 +395,7 @@ string M7(bool b)
395
395
{
396
396
var s = "" ;
397
397
if ( b )
398
- s = "abc" ; // BAD
398
+ s = "abc" ; // $ Alert
399
399
if ( ! b )
400
400
return s ;
401
401
return null ;
@@ -469,8 +469,18 @@ public static void M()
469
469
using var x = new System . IO . FileStream ( "" , System . IO . FileMode . Open ) ; // GOOD
470
470
using var _ = new System . IO . FileStream ( "" , System . IO . FileMode . Open ) ; // GOOD
471
471
472
- using ( var y = new System . IO . FileStream ( "" , System . IO . FileMode . Open ) ) // BAD
472
+ using ( var y = new System . IO . FileStream ( "" , System . IO . FileMode . Open ) ) // $ Alert
473
473
{
474
474
}
475
475
}
476
- }
476
+ }
477
+
478
+ class StringInterpolation
479
+ {
480
+ void Pi ( )
481
+ {
482
+ float pi = 3.14159f ; // GOOD
483
+ const int align = 6 ; // GOOD
484
+ Console . WriteLine ( $ "Pi, { pi , align : F3} ") ;
485
+ }
486
+ }
0 commit comments