]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] go/types: adjust logic for method expression arg naming
authorRob Findley <rfindley@google.com>
Tue, 22 Jun 2021 14:13:54 +0000 (10:13 -0400)
committerRobert Findley <rfindley@google.com>
Tue, 22 Jun 2021 17:03:28 +0000 (17:03 +0000)
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>
src/go/types/call.go

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