File tree Expand file tree Collapse file tree
lib/semmle/go/controlflow
test/query-tests/RedundantCode/UnreachableStatement Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -682,7 +682,7 @@ module CfgImpl {
682682 e .( Go:: PromotedSelector ) .refersTo ( explicitField ) and
683683 baseType .getFieldAtDepth ( _, explicitFieldDepth ) = explicitField
684684 |
685- index = explicitFieldDepth - implicitFieldDepth
685+ index = explicitFieldDepth - implicitFieldDepth and index > 0
686686 )
687687 )
688688 or
@@ -692,7 +692,8 @@ module CfgImpl {
692692 baseType = e .( Go:: PromotedSelector ) .getSelectedStructType ( ) and
693693 e .( Go:: PromotedSelector ) .refersTo ( method ) and
694694 baseType .getMethodAtDepth ( _, mDepth ) = method and
695- index = mDepth - implicitFieldDepth
695+ index = mDepth - implicitFieldDepth and
696+ index > 0
696697 |
697698 method = baseType .getMethodOfEmbedded ( implicitField , _, implicitFieldDepth + 1 )
698699 or
Original file line number Diff line number Diff line change @@ -186,4 +186,21 @@ func test23() {
186186 unreachable () // OK: deliberately unreachable
187187}
188188
189+ type (
190+ embedded struct {}
191+ recursive struct {
192+ * embedded
193+ value int
194+ * recursive
195+ }
196+ )
197+
198+ func test24 (x * recursive ) []int {
199+ values := []int {0 }
200+ if x .value != 0 {
201+ values = append (values , x .value )
202+ }
203+ return values // OK: reachable because value is a direct field of recursive
204+ }
205+
189206func main () {}
You can’t perform that action at this time.
0 commit comments