From 5c59e11f5e1fe2e6d5b684f9a348022c07807126 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Wed, 7 Jul 2021 13:18:42 -0700 Subject: [PATCH] cmd/compile: remove special-casing of blank in types.sconv{,2} 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 Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/types/fmt.go | 8 -------- test/fixedbugs/issue47087.dir/a.go | 9 +++++++++ test/fixedbugs/issue47087.dir/b.go | 9 +++++++++ test/fixedbugs/issue47087.dir/main.go | 19 +++++++++++++++++++ test/fixedbugs/issue47087.go | 7 +++++++ 5 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 test/fixedbugs/issue47087.dir/a.go create mode 100644 test/fixedbugs/issue47087.dir/b.go create mode 100644 test/fixedbugs/issue47087.dir/main.go create mode 100644 test/fixedbugs/issue47087.go diff --git a/src/cmd/compile/internal/types/fmt.go b/src/cmd/compile/internal/types/fmt.go index 7b284aa661..8b988952a7 100644 --- a/src/cmd/compile/internal/types/fmt.go +++ b/src/cmd/compile/internal/types/fmt.go @@ -109,10 +109,6 @@ func sconv(s *Sym, verb rune, mode fmtMode) string { return "" } - 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("") 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 index 0000000000..6093092ace --- /dev/null +++ b/test/fixedbugs/issue47087.dir/a.go @@ -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 index 0000000000..8f96d25a12 --- /dev/null +++ b/test/fixedbugs/issue47087.dir/b.go @@ -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 index 0000000000..ccd0891a61 --- /dev/null +++ b/test/fixedbugs/issue47087.dir/main.go @@ -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 index 0000000000..40df49f83b --- /dev/null +++ b/test/fixedbugs/issue47087.go @@ -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 -- 2.48.1