File tree 2 files changed +22
-7
lines changed
go/analysis/passes/nilness 2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -273,8 +273,12 @@ func nilnessOf(stack []fact, v ssa.Value) nilness {
273
273
* ssa.MakeClosure ,
274
274
* ssa.MakeInterface ,
275
275
* ssa.MakeMap ,
276
- * ssa.MakeSlice ,
277
- * ssa.Slice :
276
+ * ssa.MakeSlice :
277
+ return isnonnil
278
+ case * ssa.Slice :
279
+ if cons , ok := v .X .(* ssa.Const ); ok && cons .IsNil () {
280
+ return isnil
281
+ }
278
282
return isnonnil
279
283
case * ssa.Const :
280
284
if v .IsNil () {
Original file line number Diff line number Diff line change @@ -71,10 +71,6 @@ func f3() error {
71
71
if ch != nil { // want "tautological condition: non-nil != nil"
72
72
print (0 )
73
73
}
74
- slice := make ([]string , 0 )
75
- if slice == nil { // want "impossible condition: non-nil == nil"
76
- print (0 )
77
- }
78
74
return nil
79
75
}
80
76
@@ -134,7 +130,6 @@ func f9(x interface {
134
130
b ()
135
131
c ()
136
132
}) {
137
-
138
133
x .b () // we don't catch this panic because we don't have any facts yet
139
134
xx := interface {
140
135
a ()
@@ -159,6 +154,22 @@ func f9(x interface {
159
154
}
160
155
}
161
156
157
+ func f10 () {
158
+ s0 := make ([]string , 0 )
159
+ if s0 == nil { // want "impossible condition: non-nil == nil"
160
+ print (0 )
161
+ }
162
+
163
+ var s1 []string
164
+ if s1 == nil { // want "tautological condition: nil == nil"
165
+ print (0 )
166
+ }
167
+ s2 := s1 [:]
168
+ if s2 == nil { // want "tautological condition: nil == nil"
169
+ print (0 )
170
+ }
171
+ }
172
+
162
173
func unknown () bool {
163
174
return false
164
175
}
You can’t perform that action at this time.
0 commit comments