Skip to content

Commit

Permalink
analysis/code: strip pointer when printing selector for field
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikh committed Nov 6, 2021
1 parent d42e6ab commit 9a50128
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion analysis/code/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ func SelectorName(pass *analysis.Pass, expr *ast.SelectorExpr) string {
}
panic(fmt.Sprintf("unsupported selector: %v", expr))
}
return fmt.Sprintf("(%s).%s", sel.Recv(), sel.Obj().Name())
if v, ok := sel.Obj().(*types.Var); ok && v.IsField() {
return fmt.Sprintf("(%s).%s", typeutil.DereferenceR(sel.Recv()), sel.Obj().Name())
} else {
return fmt.Sprintf("(%s).%s", sel.Recv(), sel.Obj().Name())
}
}

func IsNil(pass *analysis.Pass, expr ast.Expr) bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var _ = syscall.StringByteSlice("") // want `Use ByteSliceFromString instead`

func fn1(err error) {
var r *http.Request
_ = r.Cancel // want `If a Request's Cancel field and context are both`
_ = r.Cancel
_ = syscall.StringByteSlice("") // want `Use ByteSliceFromString instead`
_ = os.SEEK_SET
var _ flate.ReadError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
var _ = syscall.StringByteSlice("") // want `Use ByteSliceFromString instead`

func fn1(err error) {
var r *http.Request
_ = r.Cancel // want `If a Request's Cancel field and context are both`
var r http.Request
var rp *http.Request
_ = r.Cancel // want `deprecated since Go 1\.7:.+If a Request's Cancel field and context are both`
_ = rp.Cancel // want `deprecated since Go 1\.7:.+If a Request's Cancel field and context are both`
_ = syscall.StringByteSlice("") // want `Use ByteSliceFromString instead`
_ = os.SEEK_SET // want `Use io\.SeekStart, io\.SeekCurrent, and io\.SeekEnd`
if err == http.ErrWriteAfterFlush { // want `ErrWriteAfterFlush is no longer`
Expand Down

0 comments on commit 9a50128

Please sign in to comment.