Skip to content

Commit 596df99

Browse files
committed
Fix bug - implicit field selection created with depth 0
1 parent 4a82483 commit 596df99

4 files changed

Lines changed: 5 additions & 9 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
@@ -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
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
consistencyOverview
2-
| deadEnd | 12 |
3-
| missingInNodeForPostOrInOrder | 1 |
2+
| deadEnd | 11 |
43
deadEnd
54
| main.go:17:2:17:10 | select statement |
65
| main.go:109:2:109:10 | select statement |
@@ -13,6 +12,3 @@ deadEnd
1312
| main.go:157:2:157:10 | select statement |
1413
| main.go:164:2:164:10 | select statement |
1514
| main.go:168:2:168:10 | select statement |
16-
| main.go:200:5:200:11 | implicit-field:0 selection of value |
17-
missingInNodeForPostOrInOrder
18-
| main.go:200:5:200:11 | selection of value |

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@
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. |
1313
| main.go:171:2:171:14 | expression statement | This statement is unreachable. |
14-
| main.go:203:2:203: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
@@ -200,7 +200,7 @@ func test24(x *recursive) []int {
200200
if x.value != 0 {
201201
values = append(values, x.value)
202202
}
203-
return values // $ SPURIOUS: Alert // BUG: reachable because value is a direct field of recursive
203+
return values // OK: reachable because value is a direct field of recursive
204204
}
205205

206206
func main() {}

0 commit comments

Comments
 (0)