File tree Expand file tree Collapse file tree
test/query-tests/RedundantCode/UnreachableStatement Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -93,8 +93,28 @@ predicate allowlist(Stmt s) {
9393 exists ( getPreviousStmt ( s ) .( IfStmt ) .getCondition ( ) .getBoolValue ( ) )
9494}
9595
96+ /** Holds if `s` is part of an allowlisted prefix of a run of unreachable statements. */
97+ predicate isInAllowlistedUnreachablePrefix ( Stmt s ) {
98+ allowlist ( s ) and
99+ (
100+ firstUnreachableStmt ( s )
101+ or
102+ isInAllowlistedUnreachablePrefix ( getPreviousStmt ( s ) )
103+ )
104+ }
105+
106+ /** Holds if `s` is the first non-allowlisted statement in a run of unreachable statements. */
107+ predicate firstNonAllowlistedUnreachableStmt ( Stmt s ) {
108+ not isReachable ( s ) and
109+ not s instanceof EmptyStmt and
110+ not allowlist ( s ) and
111+ (
112+ firstUnreachableStmt ( s )
113+ or
114+ isInAllowlistedUnreachablePrefix ( getPreviousStmt ( s ) )
115+ )
116+ }
117+
96118from Stmt s
97- where
98- firstUnreachableStmt ( s ) and
99- not allowlist ( s )
119+ where firstNonAllowlistedUnreachableStmt ( s )
100120select s , "This statement is unreachable."
Original file line number Diff line number Diff line change 1010| main.go:147:2:147:17 | return statement | This statement is unreachable. |
1111| main.go:153:2:153:22 | return statement | This statement is unreachable. |
1212| main.go:159:2:159:43 | return statement | This statement is unreachable. |
13+ | main.go:165:2:165:14 | expression statement | This statement is unreachable. |
Original file line number Diff line number Diff line change @@ -162,7 +162,7 @@ func test19() mystruct {
162162func test20 () {
163163 select {}
164164 panic ("unreachable" ) // OK: allowlisted statement
165- unreachable () // $ MISSING: Alert
165+ unreachable () // $ Alert
166166}
167167
168168func main () {}
You can’t perform that action at this time.
0 commit comments