File tree 2 files changed +24
-5
lines changed
go/analysis/passes/nilness 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -251,7 +251,7 @@ func (n nilness) String() string { return nilnessStrings[n+1] }
251
251
// or unknown given the dominating stack of facts.
252
252
func nilnessOf (stack []fact , v ssa.Value ) nilness {
253
253
switch v := v .(type ) {
254
- // unwrap ChangeInterface values recursively, to detect if underlying
254
+ // unwrap ChangeInterface and Slice values recursively, to detect if underlying
255
255
// values have any facts recorded or are otherwise known with regard to nilness.
256
256
//
257
257
// This work must be in addition to expanding facts about
@@ -265,6 +265,10 @@ func nilnessOf(stack []fact, v ssa.Value) nilness {
265
265
if underlying := nilnessOf (stack , v .X ); underlying != unknown {
266
266
return underlying
267
267
}
268
+ case * ssa.Slice :
269
+ if underlying := nilnessOf (stack , v .X ); underlying != unknown {
270
+ return underlying
271
+ }
268
272
case * ssa.SliceToArrayPointer :
269
273
nn := nilnessOf (stack , v .X )
270
274
if slice2ArrayPtrLen (v ) > 0 {
Original file line number Diff line number Diff line change @@ -130,7 +130,6 @@ func f9(x interface {
130
130
b ()
131
131
c ()
132
132
}) {
133
-
134
133
x .b () // we don't catch this panic because we don't have any facts yet
135
134
xx := interface {
136
135
a ()
@@ -155,11 +154,27 @@ func f9(x interface {
155
154
}
156
155
}
157
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
+
158
173
func unknown () bool {
159
174
return false
160
175
}
161
176
162
- func f10 (a interface {}) {
177
+ func f11 (a interface {}) {
163
178
switch a .(type ) {
164
179
case nil :
165
180
return
@@ -170,7 +185,7 @@ func f10(a interface{}) {
170
185
}
171
186
}
172
187
173
- func f11 (a interface {}) {
188
+ func f12 (a interface {}) {
174
189
switch a {
175
190
case nil :
176
191
return
@@ -190,7 +205,7 @@ type innerY struct {
190
205
value int
191
206
}
192
207
193
- func f12 () {
208
+ func f13 () {
194
209
var d * Y
195
210
print (d .value ) // want "nil dereference in field selection"
196
211
}
You can’t perform that action at this time.
0 commit comments