]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: revert internal parameter rename (from ".anonX" to "") before export
authorRobert Griesemer <gri@golang.org>
Tue, 5 Jun 2018 19:48:51 +0000 (12:48 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 5 Jun 2018 20:22:07 +0000 (20:22 +0000)
In the old binary export format, parameter names for parameter lists
which contained only types where never written, so this problem didn't
come up.

Fixes #25101.

Change-Id: Ia8b817f7f467570b05f88d584e86b6ef4acdccc6
Reviewed-on: https://go-review.googlesource.com/116376
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/dcl.go
test/fixedbugs/issue25101.go [new file with mode: 0644]

index d88c5e5c5e5427b9b182da0704a87f92d25f38f3..736ea0a018380b7dd5180c0bd66dda9df39c734b 100644 (file)
@@ -778,15 +778,26 @@ func functypefield0(t *types.Type, this *types.Field, in, out []*types.Field) {
 
 // origSym returns the original symbol written by the user.
 func origSym(s *types.Sym) *types.Sym {
-       if s != nil && s.Name[0] == '~' {
+       if s == nil {
+               return nil
+       }
+
+       if len(s.Name) > 1 && s.Name[0] == '~' {
                switch s.Name[1] {
                case 'r': // originally an unnamed result
-                       s = nil
+                       return nil
                case 'b': // originally the blank identifier _
                        // TODO(mdempsky): Does s.Pkg matter here?
-                       s = nblank.Sym
+                       return nblank.Sym
                }
+               return s
        }
+
+       if strings.HasPrefix(s.Name, ".anon") {
+               // originally an unnamed or _ name (see subr.go: structargs)
+               return nil
+       }
+
        return s
 }
 
diff --git a/test/fixedbugs/issue25101.go b/test/fixedbugs/issue25101.go
new file mode 100644 (file)
index 0000000..4fd6bed
--- /dev/null
@@ -0,0 +1,16 @@
+// compile
+
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Indexed export format must not crash when writing
+// the anonymous parameter for m.
+
+package p
+
+var x interface {
+       m(int)
+}
+
+var M = x.m