Skip to content

Commit 6a615a9

Browse files
committed
fix invalid EntryType check
1 parent c334f8a commit 6a615a9

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

contextcheck.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type entryType int
5454

5555
const (
5656
EntryNone entryType = iota
57+
EntryNormal // without ctx in
5758
EntryWithCtx // has ctx in
5859
EntryWithHttpHandler // is http handler
5960
)
@@ -133,13 +134,13 @@ func (r *runner) run(pass *analysis.Pass) {
133134
continue
134135
}
135136

136-
if entryType := r.checkIsEntry(f); entryType == EntryNone {
137+
if entryType := r.checkIsEntry(f); entryType == EntryNormal {
137138
// record the result of nomal function
138139
checkingMap := make(map[string]bool)
139140
checkingMap[key] = true
140141
r.setFact(key, r.checkFuncWithoutCtx(f, checkingMap), f.Name())
141142
continue
142-
} else {
143+
} else if entryType == EntryWithCtx || entryType == EntryWithHttpHandler {
143144
tmpFuncs = append(tmpFuncs, entryInfo{f: f, tp: entryType})
144145
}
145146
}
@@ -177,14 +178,14 @@ func (r *runner) getRequiedType(pssa *buildssa.SSA, path, name string) (obj *typ
177178
}
178179

179180
func (r *runner) collectHttpTyps(pssa *buildssa.SSA) {
180-
objRes, pobjRes, ok := r.getRequiedType(pssa, httpPkg, httpRes)
181+
objRes, _, ok := r.getRequiedType(pssa, httpPkg, httpRes)
181182
if ok {
182-
r.httpResTyps = append(r.httpResTyps, objRes, pobjRes)
183+
r.httpResTyps = append(r.httpResTyps, objRes)
183184
}
184185

185-
objReq, pobjReq, ok := r.getRequiedType(pssa, httpPkg, httpReq)
186+
_, pobjReq, ok := r.getRequiedType(pssa, httpPkg, httpReq)
186187
if ok {
187-
r.httpReqTyps = append(r.httpReqTyps, objReq, pobjReq, types.NewPointer(pobjReq))
188+
r.httpReqTyps = append(r.httpReqTyps, pobjReq)
188189
}
189190
}
190191

@@ -221,7 +222,7 @@ func (r *runner) noImportedContextAndHttp(f *ssa.Function) (ret bool) {
221222

222223
func (r *runner) checkIsEntry(f *ssa.Function) entryType {
223224
if r.noImportedContextAndHttp(f) {
224-
return EntryNone
225+
return EntryNormal
225226
}
226227

227228
ctxIn, ctxOut := r.checkIsCtx(f)
@@ -238,7 +239,7 @@ func (r *runner) checkIsEntry(f *ssa.Function) entryType {
238239
return EntryWithHttpHandler
239240
}
240241

241-
return EntryNone
242+
return EntryNormal
242243
}
243244

244245
func (r *runner) checkIsCtx(f *ssa.Function) (in, out bool) {
@@ -540,7 +541,7 @@ func (r *runner) checkFuncWithoutCtx(f *ssa.Function, checkingMap map[string]boo
540541
continue
541542
}
542543

543-
if entryType := r.checkIsEntry(ff); entryType == EntryNone {
544+
if entryType := r.checkIsEntry(ff); entryType == EntryNormal {
544545
// cannot get info from fact, skip
545546
if ff.Blocks == nil {
546547
continue

0 commit comments

Comments
 (0)