Skip to content

Commit cc16593

Browse files
committed
Fix bug - implicit field selection created with depth 0
1 parent 94c784e commit cc16593

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

‎go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ module CfgImpl {
679679
e.(Go::PromotedSelector).refersTo(explicitField) and
680680
baseType.getFieldAtDepth(_, explicitFieldDepth) = explicitField
681681
|
682-
index = explicitFieldDepth - implicitFieldDepth
682+
index = explicitFieldDepth - implicitFieldDepth and index > 0
683683
)
684684
)
685685
or
@@ -689,7 +689,8 @@ module CfgImpl {
689689
baseType = e.(Go::PromotedSelector).getSelectedStructType() and
690690
e.(Go::PromotedSelector).refersTo(method) and
691691
baseType.getMethodAtDepth(_, mDepth) = method and
692-
index = mDepth - implicitFieldDepth
692+
index = mDepth - implicitFieldDepth and
693+
index > 0
693694
|
694695
method = baseType.getMethodOfEmbedded(implicitField, _, implicitFieldDepth + 1)
695696
or

‎go/ql/test/query-tests/RedundantCode/UnreachableStatement/UnreachableStatement.expected‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@
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:176:2:176:14 | return statement | This statement is unreachable. |

‎go/ql/test/query-tests/RedundantCode/UnreachableStatement/main.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func test20(x *recursive) []int {
173173
if x.value != 0 {
174174
values = append(values, x.value)
175175
}
176-
return values // $ SPURIOUS: Alert // BUG: reachable because value is a direct field of recursive
176+
return values // OK: reachable because value is a direct field of recursive
177177
}
178178

179179
func main() {}

0 commit comments

Comments
 (0)