Skip to content

Commit

Permalink
gopls: use Func.Signature everywhere
Browse files Browse the repository at this point in the history
Updates golang/go#65917

Change-Id: I20bec8b0a1778f0d2d81f729d12ba966799c7805
Reviewed-on: https://go-review.googlesource.com/c/tools/+/612037
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
adonovan authored and gopherbot committed Sep 9, 2024
1 parent 6b0cfff commit c2e057b
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gopls/internal/cache/methodsets/methodsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func fingerprint(method *types.Func) (string, bool) {
}

buf.WriteString(method.Id()) // e.g. "pkg.Type"
sig := method.Type().(*types.Signature)
sig := method.Signature()
fprint(sig.Params())
fprint(sig.Results())
return buf.String(), tricky
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/golang/code_lens.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func matchTestFunc(fn *ast.FuncDecl, info *types.Info, nameRe *regexp.Regexp, pa
if !ok {
return false
}
sig := obj.Type().(*types.Signature)
sig := obj.Signature()
// Test functions should have only one parameter.
if sig.Params().Len() != 1 {
return false
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/golang/codeaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ func getGoAssemblyAction(view *cache.View, pkg *cache.Package, pgf *parsego.File
if len(path) >= 2 { // [... FuncDecl File]
if decl, ok := path[len(path)-2].(*ast.FuncDecl); ok {
if fn, ok := pkg.TypesInfo().Defs[decl.Name].(*types.Func); ok {
sig := fn.Type().(*types.Signature)
sig := fn.Signature()

// Compute the linker symbol of the enclosing function.
var sym strings.Builder
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/golang/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ func (c *completer) populateCommentCompletions(comment *ast.CommentGroup) {

// collect receiver struct fields
if node.Recv != nil {
sig := c.pkg.TypesInfo().Defs[node.Name].(*types.Func).Type().(*types.Signature)
sig := c.pkg.TypesInfo().Defs[node.Name].(*types.Func).Signature()
_, named := typesinternal.ReceiverNamed(sig.Recv()) // may be nil if ill-typed
if named != nil {
if recvStruct, ok := named.Underlying().(*types.Struct); ok {
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/golang/completion/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (c *completer) item(ctx context.Context, cand candidate) (CompletionItem, e
break
}
case *types.Func:
if obj.Type().(*types.Signature).Recv() == nil {
if obj.Signature().Recv() == nil {
kind = protocol.FunctionCompletion
} else {
kind = protocol.MethodCompletion
Expand Down
6 changes: 3 additions & 3 deletions gopls/internal/golang/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func hover(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, pp pro
var recv types.Object
switch obj := obj.(type) {
case *types.Func:
sig := obj.Type().(*types.Signature)
sig := obj.Signature()
if sig.Recv() != nil {
tname := typeToObject(sig.Recv().Type())
if tname != nil { // beware typed nil
Expand Down Expand Up @@ -962,7 +962,7 @@ func objectString(obj types.Object, qf types.Qualifier, declPos token.Pos, file
// specifically, we show the receiver name,
// and replace the period in (T).f by a space (#62190).

sig := obj.Type().(*types.Signature)
sig := obj.Signature()

var buf bytes.Buffer
buf.WriteString("func ")
Expand Down Expand Up @@ -1236,7 +1236,7 @@ func StdSymbolOf(obj types.Object) *stdlib.Symbol {

// Handle Method.
if fn, _ := obj.(*types.Func); fn != nil {
isPtr, named := typesinternal.ReceiverNamed(fn.Type().(*types.Signature).Recv())
isPtr, named := typesinternal.ReceiverNamed(fn.Signature().Recv())
if isPackageLevel(named.Obj()) {
for _, s := range symbols {
if s.Kind != stdlib.Method {
Expand Down
4 changes: 2 additions & 2 deletions gopls/internal/golang/implementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func implementations(ctx context.Context, snapshot *cache.Snapshot, fh file.Hand
return obj.Type(), ""
case *types.Func:
// For methods, use the receiver type, which may be anonymous.
if recv := obj.Type().(*types.Signature).Recv(); recv != nil {
if recv := obj.Signature().Recv(); recv != nil {
return recv.Type(), obj.Id()
}
}
Expand Down Expand Up @@ -317,7 +317,7 @@ func implementsObj(ctx context.Context, snapshot *cache.Snapshot, uri protocol.D
case *types.TypeName:
// ok
case *types.Func:
if obj.Type().(*types.Signature).Recv() == nil {
if obj.Signature().Recv() == nil {
return nil, nil, fmt.Errorf("%s is a function, not a method", id.Name)
}
case nil:
Expand Down
10 changes: 5 additions & 5 deletions gopls/internal/golang/pkgdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func DocFragment(pkg *cache.Package, pgf *parsego.File, start, end token.Pos) (p
if !sym.Exported() {
// Unexported method of exported type?
if fn, ok := sym.(*types.Func); ok {
if recv := fn.Type().(*types.Signature).Recv(); recv != nil {
if recv := fn.Signature().Recv(); recv != nil {
_, named := typesinternal.ReceiverNamed(recv)
if named != nil && named.Obj().Exported() {
sym = named.Obj()
Expand All @@ -147,7 +147,7 @@ func DocFragment(pkg *cache.Package, pgf *parsego.File, start, end token.Pos) (p
// Inv: sym is field or method, or local.
switch sym := sym.(type) {
case *types.Func: // => method
sig := sym.Type().(*types.Signature)
sig := sym.Signature()
isPtr, named := typesinternal.ReceiverNamed(sig.Recv())
if named != nil {
if !named.Obj().Exported() {
Expand Down Expand Up @@ -469,7 +469,7 @@ window.addEventListener('load', function() {
label := obj.Name() // for a type
if fn, ok := obj.(*types.Func); ok {
var buf strings.Builder
sig := fn.Type().(*types.Signature)
sig := fn.Signature()
if sig.Recv() != nil {
fmt.Fprintf(&buf, "(%s) ", sig.Recv().Name())
fragment = recvType + "." + fn.Name()
Expand Down Expand Up @@ -551,7 +551,7 @@ window.addEventListener('load', function() {

// method of package-level named type?
if fn, ok := obj.(*types.Func); ok {
sig := fn.Type().(*types.Signature)
sig := fn.Signature()
if sig.Recv() != nil {
_, named := typesinternal.ReceiverNamed(sig.Recv())
if named != nil {
Expand Down Expand Up @@ -648,7 +648,7 @@ window.addEventListener('load', function() {
fnString := func(fn *types.Func) string {
pkgRelative := typesinternal.NameRelativeTo(pkg.Types())

sig := fn.Type().(*types.Signature)
sig := fn.Signature()

// Emit "func (recv T) F".
var buf bytes.Buffer
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/golang/references.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ func localReferences(pkg *cache.Package, targets map[types.Object]bool, correspo
// comparisons for obj, if it is a method, or nil otherwise.
func effectiveReceiver(obj types.Object) types.Type {
if fn, ok := obj.(*types.Func); ok {
if recv := fn.Type().(*types.Signature).Recv(); recv != nil {
if recv := fn.Signature().Recv(); recv != nil {
return methodsets.EnsurePointer(recv.Type())
}
}
Expand Down
6 changes: 3 additions & 3 deletions gopls/internal/golang/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func renameOrdinary(ctx context.Context, snapshot *cache.Snapshot, f file.Handle
// contain a reference (xrefs) to the target field.

case *types.Func:
if obj.Type().(*types.Signature).Recv() != nil {
if obj.Signature().Recv() != nil {
transitive = true // method
}

Expand Down Expand Up @@ -978,7 +978,7 @@ func renameObjects(newName string, pkg *cache.Package, targets ...types.Object)
// TODO(adonovan): pull this into the caller.
for _, obj := range targets {
if obj, ok := obj.(*types.Func); ok {
recv := obj.Type().(*types.Signature).Recv()
recv := obj.Signature().Recv()
if recv != nil && types.IsInterface(recv.Type().Underlying()) {
r.changeMethods = true
break
Expand Down Expand Up @@ -1168,7 +1168,7 @@ func (r *renamer) updateCommentDocLinks() (map[protocol.DocumentURI][]diff.Edit,
if !isFunc {
continue
}
recv := obj.Type().(*types.Signature).Recv()
recv := obj.Signature().Recv()
if recv == nil {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/golang/rename_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ func (r *renamer) satisfy() map[satisfy.Constraint]bool {

// recv returns the method's receiver.
func recv(meth *types.Func) *types.Var {
return meth.Type().(*types.Signature).Recv()
return meth.Signature().Recv()
}

// someUse returns an arbitrary use of obj within info.
Expand Down
4 changes: 2 additions & 2 deletions gopls/internal/golang/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func stubMethodsFixer(ctx context.Context, snapshot *cache.Snapshot, pkg *cache.
// Otherwise, use lowercase for the first letter of the object.
rn := strings.ToLower(si.Concrete.Obj().Name()[0:1])
for i := 0; i < si.Concrete.NumMethods(); i++ {
if recv := si.Concrete.Method(i).Type().(*types.Signature).Recv(); recv.Name() != "" {
if recv := si.Concrete.Method(i).Signature().Recv(); recv.Name() != "" {
rn = recv.Name()
break
}
Expand All @@ -229,7 +229,7 @@ func stubMethodsFixer(ctx context.Context, snapshot *cache.Snapshot, pkg *cache.

for index := range missing {
mrn := rn + " "
sig := missing[index].fn.Type().(*types.Signature)
sig := missing[index].fn.Signature()
if checkRecvName(sig.Params()) || checkRecvName(sig.Results()) {
mrn = ""
}
Expand Down

0 comments on commit c2e057b

Please sign in to comment.