diff --git a/contextcheck.go b/contextcheck.go index 6352191..45b6274 100644 --- a/contextcheck.go +++ b/contextcheck.go @@ -54,6 +54,7 @@ type entryType int const ( EntryNone entryType = iota + EntryNormal // without ctx in EntryWithCtx // has ctx in EntryWithHttpHandler // is http handler ) @@ -133,13 +134,13 @@ func (r *runner) run(pass *analysis.Pass) { continue } - if entryType := r.checkIsEntry(f); entryType == EntryNone { + if entryType := r.checkIsEntry(f); entryType == EntryNormal { // record the result of nomal function checkingMap := make(map[string]bool) checkingMap[key] = true r.setFact(key, r.checkFuncWithoutCtx(f, checkingMap), f.Name()) continue - } else { + } else if entryType == EntryWithCtx || entryType == EntryWithHttpHandler { tmpFuncs = append(tmpFuncs, entryInfo{f: f, tp: entryType}) } } @@ -177,14 +178,14 @@ func (r *runner) getRequiedType(pssa *buildssa.SSA, path, name string) (obj *typ } func (r *runner) collectHttpTyps(pssa *buildssa.SSA) { - objRes, pobjRes, ok := r.getRequiedType(pssa, httpPkg, httpRes) + objRes, _, ok := r.getRequiedType(pssa, httpPkg, httpRes) if ok { - r.httpResTyps = append(r.httpResTyps, objRes, pobjRes) + r.httpResTyps = append(r.httpResTyps, objRes) } - objReq, pobjReq, ok := r.getRequiedType(pssa, httpPkg, httpReq) + _, pobjReq, ok := r.getRequiedType(pssa, httpPkg, httpReq) if ok { - r.httpReqTyps = append(r.httpReqTyps, objReq, pobjReq, types.NewPointer(pobjReq)) + r.httpReqTyps = append(r.httpReqTyps, pobjReq) } } @@ -221,7 +222,7 @@ func (r *runner) noImportedContextAndHttp(f *ssa.Function) (ret bool) { func (r *runner) checkIsEntry(f *ssa.Function) entryType { if r.noImportedContextAndHttp(f) { - return EntryNone + return EntryNormal } ctxIn, ctxOut := r.checkIsCtx(f) @@ -238,7 +239,7 @@ func (r *runner) checkIsEntry(f *ssa.Function) entryType { return EntryWithHttpHandler } - return EntryNone + return EntryNormal } 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 continue } - if entryType := r.checkIsEntry(ff); entryType == EntryNone { + if entryType := r.checkIsEntry(ff); entryType == EntryNormal { // cannot get info from fact, skip if ff.Blocks == nil { continue