Skip to content

Commit 2dcfdaa

Browse files
Remove Roslyn Control flow analysis calls
1 parent 4916574 commit 2dcfdaa

File tree

2 files changed

+16
-30
lines changed

2 files changed

+16
-30
lines changed

CheckedExceptions.Tests/TryCatchTest2.cs

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -343,16 +343,8 @@ static int ReadAndParse()
343343
344344
try
345345
{
346-
bool x = true;
347-
if (x)
348-
{
349-
//May throw FormatException, or OverflowException, or return
350-
return int.Parse(input);
351-
}
352-
else
353-
{
354-
throw new InvalidCastException();
355-
}
346+
//May throw FormatException, or OverflowException, or return
347+
return int.Parse(input);
356348
}
357349
catch (FormatException ex)
358350
{
@@ -372,19 +364,17 @@ static int ReadAndParse()
372364
}
373365
""";
374366

375-
/*
376-
var expected = Verifier.Diagnostic(CheckedExceptionsAnalyzer.DiagnosticIdRedundantExceptionDeclaration)
377-
.WithArguments("ArgumentException")
378-
.WithSpan(11, 55, 11, 72);
367+
var expected = Verifier.Diagnostic(CheckedExceptionsAnalyzer.DiagnosticIdRedundantExceptionDeclaration)
368+
.WithArguments("ArgumentException")
369+
.WithSpan(11, 55, 11, 72);
379370

380-
var expected2 = Verifier.Diagnostic(CheckedExceptionsAnalyzer.DiagnosticIdRedundantCatchAllClause)
381-
.WithArguments("ArgumentException")
382-
.WithSpan(32, 9, 32, 14);
383-
*/
371+
var expected2 = Verifier.Diagnostic(CheckedExceptionsAnalyzer.DiagnosticIdRedundantCatchAllClause)
372+
.WithArguments("ArgumentException")
373+
.WithSpan(29, 9, 29, 14);
384374

385375
await Verifier.VerifyAnalyzerAsync(test, o =>
386376
{
387-
//o.ExpectedDiagnostics.AddRange(expected, expected2);
377+
o.ExpectedDiagnostics.AddRange(expected, expected2);
388378

389379
o.DisabledDiagnostics.Remove(CheckedExceptionsAnalyzer.DiagnosticIdRedundantExceptionDeclaration);
390380
});
@@ -436,17 +426,13 @@ static int ReadAndParse()
436426
}
437427
""";
438428

439-
var expected = Verifier.Diagnostic(CheckedExceptionsAnalyzer.DiagnosticIdRedundantExceptionDeclaration)
440-
.WithArguments("InvalidUserInputException")
441-
.WithSpan(11, 20, 11, 45);
442-
443-
var expected2 = Verifier.Diagnostic(CheckedExceptionsAnalyzer.DiagnosticIdRedundantCatchAllClause)
429+
var expected = Verifier.Diagnostic(CheckedExceptionsAnalyzer.DiagnosticIdRedundantCatchAllClause)
444430
.WithArguments("ArgumentException")
445431
.WithSpan(33, 9, 33, 14);
446432

447433
await Verifier.VerifyAnalyzerAsync(test, o =>
448434
{
449-
o.ExpectedDiagnostics.AddRange(expected, expected2);
435+
o.ExpectedDiagnostics.AddRange(expected);
450436

451437
o.DisabledDiagnostics.Remove(CheckedExceptionsAnalyzer.DiagnosticIdRedundantExceptionDeclaration);
452438
});

CheckedExceptions/CheckedExceptionsAnalyzer.ControlFlow.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ private FlowWithExceptionsResult AnalyzeBlockWithExceptions(
274274
{
275275
var flow = semanticModel.AnalyzeControlFlow(node);
276276

277-
if (!flow.Succeeded || !flow.StartPointIsReachable)
278-
return FlowWithExceptionsResult.Unreachable;
277+
//if (!flow.Succeeded || !flow.StartPointIsReachable)
278+
// return FlowWithExceptionsResult.Unreachable;
279279
}
280280

281281
var unhandled = new HashSet<INamedTypeSymbol>(SymbolEqualityComparer.Default);
@@ -300,7 +300,7 @@ private FlowWithExceptionsResult AnalyzeBlockWithExceptions(
300300
{
301301
if (!reachable)
302302
{
303-
var statementIndex = statements.TakeWhile(x => x != statement).Count();
303+
var statementIndex = statements.TakeWhile(x => x != statement).Count() - 1;
304304

305305
// 🚩 We already know the block can’t continue past here
306306
for (int i = statementIndex; i < statements.Count(); i++)
@@ -370,8 +370,8 @@ private FlowWithExceptionsResult AnalyzeStatementWithExceptions(
370370
// Control flow for this single statement
371371
var flow = semanticModel.AnalyzeControlFlow(statement);
372372

373-
if (!flow.Succeeded || !flow.StartPointIsReachable)
374-
return FlowWithExceptionsResult.Unreachable;
373+
//if (!flow.Succeeded || !flow.StartPointIsReachable)
374+
// return FlowWithExceptionsResult.Unreachable;
375375

376376
// Handle nested blocks
377377
if (statement is BlockSyntax block)

0 commit comments

Comments
 (0)