1
0
mirror of https://github.com/golang/go synced 2024-11-14 07:00:21 -07:00

[dev.typeparams] go/types: adjust logic for method expression arg naming

CL 325369 improved this logic in types2. Port this improvement back to
go/types.

Change-Id: I5f859cbffd88bb3db09a81c2389269f7bd0869f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/330069
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Rob Findley 2021-06-22 10:13:54 -04:00 committed by Robert Findley
parent 541612b974
commit 62095c66e0

View File

@ -587,16 +587,15 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr) {
if sig.params != nil { if sig.params != nil {
params = sig.params.vars params = sig.params.vars
} }
// Be consistent about named/unnamed parameters. // Be consistent about named/unnamed parameters. This is not needed
needName := true // for type-checking, but the newly constructed signature may appear
for _, param := range params { // in an error message and then have mixed named/unnamed parameters.
if param.Name() == "" { // (An alternative would be to not print parameter names in errors,
needName = false // but it's useful to see them; this is cheap and method expressions
break // are rare.)
}
}
name := "" name := ""
if needName { if len(params) > 0 && params[0].name != "" {
// name needed
name = sig.recv.name name = sig.recv.name
if name == "" { if name == "" {
name = "_" name = "_"