Skip to content

Commit c2e057b

Browse files
adonovangopherbot
authored andcommitted
gopls: use Func.Signature everywhere
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>
1 parent 6b0cfff commit c2e057b

File tree

12 files changed

+22
-22
lines changed

12 files changed

+22
-22
lines changed

gopls/internal/cache/methodsets/methodsets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ func fingerprint(method *types.Func) (string, bool) {
449449
}
450450

451451
buf.WriteString(method.Id()) // e.g. "pkg.Type"
452-
sig := method.Type().(*types.Signature)
452+
sig := method.Signature()
453453
fprint(sig.Params())
454454
fprint(sig.Results())
455455
return buf.String(), tricky

gopls/internal/golang/code_lens.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func matchTestFunc(fn *ast.FuncDecl, info *types.Info, nameRe *regexp.Regexp, pa
129129
if !ok {
130130
return false
131131
}
132-
sig := obj.Type().(*types.Signature)
132+
sig := obj.Signature()
133133
// Test functions should have only one parameter.
134134
if sig.Params().Len() != 1 {
135135
return false

gopls/internal/golang/codeaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ func getGoAssemblyAction(view *cache.View, pkg *cache.Package, pgf *parsego.File
597597
if len(path) >= 2 { // [... FuncDecl File]
598598
if decl, ok := path[len(path)-2].(*ast.FuncDecl); ok {
599599
if fn, ok := pkg.TypesInfo().Defs[decl.Name].(*types.Func); ok {
600-
sig := fn.Type().(*types.Signature)
600+
sig := fn.Signature()
601601

602602
// Compute the linker symbol of the enclosing function.
603603
var sym strings.Builder

gopls/internal/golang/completion/completion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ func (c *completer) populateCommentCompletions(comment *ast.CommentGroup) {
10361036

10371037
// collect receiver struct fields
10381038
if node.Recv != nil {
1039-
sig := c.pkg.TypesInfo().Defs[node.Name].(*types.Func).Type().(*types.Signature)
1039+
sig := c.pkg.TypesInfo().Defs[node.Name].(*types.Func).Signature()
10401040
_, named := typesinternal.ReceiverNamed(sig.Recv()) // may be nil if ill-typed
10411041
if named != nil {
10421042
if recvStruct, ok := named.Underlying().(*types.Struct); ok {

gopls/internal/golang/completion/format.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (c *completer) item(ctx context.Context, cand candidate) (CompletionItem, e
9595
break
9696
}
9797
case *types.Func:
98-
if obj.Type().(*types.Signature).Recv() == nil {
98+
if obj.Signature().Recv() == nil {
9999
kind = protocol.FunctionCompletion
100100
} else {
101101
kind = protocol.MethodCompletion

gopls/internal/golang/hover.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ func hover(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, pp pro
535535
var recv types.Object
536536
switch obj := obj.(type) {
537537
case *types.Func:
538-
sig := obj.Type().(*types.Signature)
538+
sig := obj.Signature()
539539
if sig.Recv() != nil {
540540
tname := typeToObject(sig.Recv().Type())
541541
if tname != nil { // beware typed nil
@@ -962,7 +962,7 @@ func objectString(obj types.Object, qf types.Qualifier, declPos token.Pos, file
962962
// specifically, we show the receiver name,
963963
// and replace the period in (T).f by a space (#62190).
964964

965-
sig := obj.Type().(*types.Signature)
965+
sig := obj.Signature()
966966

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

12371237
// Handle Method.
12381238
if fn, _ := obj.(*types.Func); fn != nil {
1239-
isPtr, named := typesinternal.ReceiverNamed(fn.Type().(*types.Signature).Recv())
1239+
isPtr, named := typesinternal.ReceiverNamed(fn.Signature().Recv())
12401240
if isPackageLevel(named.Obj()) {
12411241
for _, s := range symbols {
12421242
if s.Kind != stdlib.Method {

gopls/internal/golang/implementation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func implementations(ctx context.Context, snapshot *cache.Snapshot, fh file.Hand
126126
return obj.Type(), ""
127127
case *types.Func:
128128
// For methods, use the receiver type, which may be anonymous.
129-
if recv := obj.Type().(*types.Signature).Recv(); recv != nil {
129+
if recv := obj.Signature().Recv(); recv != nil {
130130
return recv.Type(), obj.Id()
131131
}
132132
}
@@ -317,7 +317,7 @@ func implementsObj(ctx context.Context, snapshot *cache.Snapshot, uri protocol.D
317317
case *types.TypeName:
318318
// ok
319319
case *types.Func:
320-
if obj.Type().(*types.Signature).Recv() == nil {
320+
if obj.Signature().Recv() == nil {
321321
return nil, nil, fmt.Errorf("%s is a function, not a method", id.Name)
322322
}
323323
case nil:

gopls/internal/golang/pkgdoc.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func DocFragment(pkg *cache.Package, pgf *parsego.File, start, end token.Pos) (p
120120
if !sym.Exported() {
121121
// Unexported method of exported type?
122122
if fn, ok := sym.(*types.Func); ok {
123-
if recv := fn.Type().(*types.Signature).Recv(); recv != nil {
123+
if recv := fn.Signature().Recv(); recv != nil {
124124
_, named := typesinternal.ReceiverNamed(recv)
125125
if named != nil && named.Obj().Exported() {
126126
sym = named.Obj()
@@ -147,7 +147,7 @@ func DocFragment(pkg *cache.Package, pgf *parsego.File, start, end token.Pos) (p
147147
// Inv: sym is field or method, or local.
148148
switch sym := sym.(type) {
149149
case *types.Func: // => method
150-
sig := sym.Type().(*types.Signature)
150+
sig := sym.Signature()
151151
isPtr, named := typesinternal.ReceiverNamed(sig.Recv())
152152
if named != nil {
153153
if !named.Obj().Exported() {
@@ -469,7 +469,7 @@ window.addEventListener('load', function() {
469469
label := obj.Name() // for a type
470470
if fn, ok := obj.(*types.Func); ok {
471471
var buf strings.Builder
472-
sig := fn.Type().(*types.Signature)
472+
sig := fn.Signature()
473473
if sig.Recv() != nil {
474474
fmt.Fprintf(&buf, "(%s) ", sig.Recv().Name())
475475
fragment = recvType + "." + fn.Name()
@@ -551,7 +551,7 @@ window.addEventListener('load', function() {
551551

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

651-
sig := fn.Type().(*types.Signature)
651+
sig := fn.Signature()
652652

653653
// Emit "func (recv T) F".
654654
var buf bytes.Buffer

gopls/internal/golang/references.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ func localReferences(pkg *cache.Package, targets map[types.Object]bool, correspo
615615
// comparisons for obj, if it is a method, or nil otherwise.
616616
func effectiveReceiver(obj types.Object) types.Type {
617617
if fn, ok := obj.(*types.Func); ok {
618-
if recv := fn.Type().(*types.Signature).Recv(); recv != nil {
618+
if recv := fn.Signature().Recv(); recv != nil {
619619
return methodsets.EnsurePointer(recv.Type())
620620
}
621621
}

gopls/internal/golang/rename.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ func renameOrdinary(ctx context.Context, snapshot *cache.Snapshot, f file.Handle
426426
// contain a reference (xrefs) to the target field.
427427

428428
case *types.Func:
429-
if obj.Type().(*types.Signature).Recv() != nil {
429+
if obj.Signature().Recv() != nil {
430430
transitive = true // method
431431
}
432432

@@ -978,7 +978,7 @@ func renameObjects(newName string, pkg *cache.Package, targets ...types.Object)
978978
// TODO(adonovan): pull this into the caller.
979979
for _, obj := range targets {
980980
if obj, ok := obj.(*types.Func); ok {
981-
recv := obj.Type().(*types.Signature).Recv()
981+
recv := obj.Signature().Recv()
982982
if recv != nil && types.IsInterface(recv.Type().Underlying()) {
983983
r.changeMethods = true
984984
break
@@ -1168,7 +1168,7 @@ func (r *renamer) updateCommentDocLinks() (map[protocol.DocumentURI][]diff.Edit,
11681168
if !isFunc {
11691169
continue
11701170
}
1171-
recv := obj.Type().(*types.Signature).Recv()
1171+
recv := obj.Signature().Recv()
11721172
if recv == nil {
11731173
continue
11741174
}

gopls/internal/golang/rename_check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ func (r *renamer) satisfy() map[satisfy.Constraint]bool {
883883

884884
// recv returns the method's receiver.
885885
func recv(meth *types.Func) *types.Var {
886-
return meth.Type().(*types.Signature).Recv()
886+
return meth.Signature().Recv()
887887
}
888888

889889
// someUse returns an arbitrary use of obj within info.

gopls/internal/golang/stub.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func stubMethodsFixer(ctx context.Context, snapshot *cache.Snapshot, pkg *cache.
208208
// Otherwise, use lowercase for the first letter of the object.
209209
rn := strings.ToLower(si.Concrete.Obj().Name()[0:1])
210210
for i := 0; i < si.Concrete.NumMethods(); i++ {
211-
if recv := si.Concrete.Method(i).Type().(*types.Signature).Recv(); recv.Name() != "" {
211+
if recv := si.Concrete.Method(i).Signature().Recv(); recv.Name() != "" {
212212
rn = recv.Name()
213213
break
214214
}
@@ -229,7 +229,7 @@ func stubMethodsFixer(ctx context.Context, snapshot *cache.Snapshot, pkg *cache.
229229

230230
for index := range missing {
231231
mrn := rn + " "
232-
sig := missing[index].fn.Type().(*types.Signature)
232+
sig := missing[index].fn.Signature()
233233
if checkRecvName(sig.Params()) || checkRecvName(sig.Results()) {
234234
mrn = ""
235235
}

0 commit comments

Comments
 (0)