]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove special-casing of blank in types.sconv{,2}
authorMatthew Dempsky <mdempsky@google.com>
Wed, 7 Jul 2021 20:18:42 +0000 (13:18 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 7 Jul 2021 22:29:01 +0000 (22:29 +0000)
I'm not sure why blank was special-cased here before, but it's
wrong. Blank is a non-exported identifier, and writing it out without
package-qualification can result in linker symbol collisions.

Fixes #47087.

Change-Id: Ie600037c8e54e3d4fdaeec21e2ca212badbd830b
Reviewed-on: https://go-review.googlesource.com/c/go/+/333163
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/types/fmt.go
test/fixedbugs/issue47087.dir/a.go [new file with mode: 0644]
test/fixedbugs/issue47087.dir/b.go [new file with mode: 0644]
test/fixedbugs/issue47087.dir/main.go [new file with mode: 0644]
test/fixedbugs/issue47087.go [new file with mode: 0644]

index 7b284aa661464b952d9fe1ded7bdc17d715d0cb4..8b988952a78d2c689714ddfe2d61260fcdb75e19 100644 (file)
@@ -109,10 +109,6 @@ func sconv(s *Sym, verb rune, mode fmtMode) string {
                return "<S>"
        }
 
-       if s.Name == "_" {
-               return "_"
-       }
-
        q := pkgqual(s.Pkg, verb, mode)
        if q == "" {
                return s.Name
@@ -136,10 +132,6 @@ func sconv2(b *bytes.Buffer, s *Sym, verb rune, mode fmtMode) {
                b.WriteString("<S>")
                return
        }
-       if s.Name == "_" {
-               b.WriteString("_")
-               return
-       }
 
        symfmt(b, s, verb, mode)
 }
diff --git a/test/fixedbugs/issue47087.dir/a.go b/test/fixedbugs/issue47087.dir/a.go
new file mode 100644 (file)
index 0000000..6093092
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2021 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.
+
+package a
+
+func F() interface{} { return struct{ _ []int }{} }
+
+var X = F()
diff --git a/test/fixedbugs/issue47087.dir/b.go b/test/fixedbugs/issue47087.dir/b.go
new file mode 100644 (file)
index 0000000..8f96d25
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2021 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.
+
+package b
+
+func F() interface{} { return struct{ _ []int }{} }
+
+var X = F()
diff --git a/test/fixedbugs/issue47087.dir/main.go b/test/fixedbugs/issue47087.dir/main.go
new file mode 100644 (file)
index 0000000..ccd0891
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2021 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.
+
+package main
+
+import (
+       "a"
+       "b"
+)
+
+func main() {
+       if a.F() == b.F() {
+               panic("FAIL")
+       }
+       if a.X == b.X {
+               panic("FAIL")
+       }
+}
diff --git a/test/fixedbugs/issue47087.go b/test/fixedbugs/issue47087.go
new file mode 100644 (file)
index 0000000..40df49f
--- /dev/null
@@ -0,0 +1,7 @@
+// rundir
+
+// Copyright 2021 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.
+
+package ignored