Skip to content

Commit b9e18f0

Browse files
committed
Changed to perform null check recursively.
1 parent b22d8f6 commit b9e18f0

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

go/analysis/passes/nilness/nilness.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,11 @@ func nilnessOf(stack []fact, v ssa.Value) nilness {
276276
*ssa.MakeSlice:
277277
return isnonnil
278278
case *ssa.Slice:
279-
if cons, ok := v.X.(*ssa.Const); ok && cons.IsNil() {
280-
return isnil
279+
// unwrap Slice values recursively, to detect if underlying
280+
// values have any facts recorded or are otherwise known with regard to nilness.
281+
if underlying := nilnessOf(stack, v.X); underlying != unknown {
282+
return underlying
281283
}
282-
return isnonnil
283284
case *ssa.Const:
284285
if v.IsNil() {
285286
return isnil

go/analysis/passes/nilness/testdata/src/a/a.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func f10() {
164164
if s1 == nil { // want "tautological condition: nil == nil"
165165
print(0)
166166
}
167-
s2 := s1[:]
167+
s2 := s1[:][:]
168168
if s2 == nil { // want "tautological condition: nil == nil"
169169
print(0)
170170
}

0 commit comments

Comments
 (0)