17
17
namespace Rubberduck . Inspections . Concrete . UnreachableCaseInspection
18
18
{
19
19
/// <summary>
20
- /// Flags 'Case' blocks that are semantically unreachable .
20
+ /// Flags 'Case' blocks that will never execute .
21
21
/// </summary>
22
22
/// <why>
23
23
/// Unreachable code is certainly unintended, and is probably either redundant, or a bug.
@@ -41,6 +41,76 @@ namespace Rubberduck.Inspections.Concrete.UnreachableCaseInspection
41
41
/// End Sub
42
42
/// ]]>
43
43
/// </example>
44
+ /// <example hasResults="true">
45
+ /// <![CDATA[
46
+ ///
47
+ /// 'If the cumulative result of multiple 'Case' statements
48
+ /// 'cover the entire range of possible values for a data type,
49
+ /// 'then all remaining 'Case' statements are unreachable
50
+ ///
51
+ /// Private Sub ExampleAllValuesCoveredIntegral(ByVal value As Long, ByVal result As Long)
52
+ /// Select Case result
53
+ /// Case Is < 100
54
+ /// ' ...
55
+ /// Case Is > -100
56
+ /// ' ...
57
+ /// 'all possible values are covered by preceding 'Case' statements
58
+ /// Case value * value ' unreachable
59
+ /// ' ...
60
+ /// Case value + value ' unreachable
61
+ /// ' ...
62
+ /// Case Else ' unreachable
63
+ /// ' ...
64
+ /// End Select
65
+ /// End Sub
66
+ /// ]]>
67
+ /// </example>
68
+ /// <example hasResults="true">
69
+ /// <![CDATA[
70
+ /// Public Enum ProductID
71
+ /// Widget = 1
72
+ /// Gadget = 2
73
+ /// Gizmo = 3
74
+ /// End Enum
75
+ ///
76
+ /// Public Sub ExampleEnumCaseElse(ByVal product As ProductID)
77
+ ///
78
+ /// 'Enums are evaluated as the 'Long' type, so even though all the
79
+ /// 'ProductID enum values have a 'Case' statement, the 'Case Else'
80
+ /// 'can still be reached for any value of the 'product' parameter that is not
81
+ /// 'a ProductID.
82
+ ///
83
+ /// Select Case product
84
+ /// Case Widget
85
+ /// ' ...
86
+ /// Case Gadget
87
+ /// ' ...
88
+ /// Case Gizmo
89
+ /// ' ...
90
+ /// Case Else 'is reachable
91
+ /// ' Raise an error for unrecognized/unhandled ProductID
92
+ /// End Select
93
+ /// End Sub
94
+ /// ]]>
95
+ /// </example>
96
+ /// <example hasResults="true">
97
+ /// <![CDATA[
98
+ ///
99
+ /// 'The inspecion flags Range Clauses that are not of the required form:
100
+ /// '[x] To [y] where [x] less than or equal to [y]
101
+ ///
102
+ /// Private Sub ExampleInvalidRangeExpression(ByVal value As String)
103
+ /// Select Case value
104
+ /// Case "Beginning" To "End"
105
+ /// ' ...
106
+ /// Case "Start" To "Finish" ' unreachable: incorrect form.
107
+ /// ' ...
108
+ /// CaseElse
109
+ /// ' ...
110
+ /// End Select
111
+ /// End Sub
112
+ /// ]]>
113
+ /// </example>
44
114
public sealed class UnreachableCaseInspection : ParseTreeInspectionBase
45
115
{
46
116
private readonly IUnreachableCaseInspectorFactory _unreachableCaseInspectorFactory ;
0 commit comments