mirror of
https://github.com/golang/go
synced 2024-09-04 23:44:16 +00:00
cmd/compile: print struct tags in var decl in inlined func body
This bug was introduced in golang.org/cl/18217, while trying to fix #13777. Originally I wanted to just disable inlining for the case being handled incorrectly, but it's fairly difficult to detect and much easier just to fix. Since the case being handled incorrectly was inlined correctly in Go 1.5, not inlining it would also be somewhat of a regression. So just fix it. Test case copied from Ian's CL 19520. The mistake to worry about in this CL would be relaxing the condition too much (we now print the note more often than we did yesterday). To confirm that we'd catch this mistake, I checked that changing (!fmtbody || !t.Funarg) to (true) does cause fixedbugs/issue13777.go to fail. And putting it back to what is written in this CL makes that test pass again as well as the new fixedbugs/issue14331.go. So I believe that the new condition is correct for both constraints. Fixes #14331. Change-Id: I91f75a4d5d07c53af5caea1855c780d9874b8df6 Reviewed-on: https://go-review.googlesource.com/19514 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
e136cac48c
commit
feb2a5d610
|
@ -748,7 +748,13 @@ func typefmt(t *Type, flag int) string {
|
||||||
if name != "" {
|
if name != "" {
|
||||||
str = name + " " + typ
|
str = name + " " + typ
|
||||||
}
|
}
|
||||||
if flag&obj.FmtShort == 0 && !fmtbody && t.Note != nil {
|
|
||||||
|
// The fmtbody flag is intended to suppress escape analysis annotations
|
||||||
|
// when printing a function type used in a function body.
|
||||||
|
// (The escape analysis tags do not apply to func vars.)
|
||||||
|
// But it must not suppress struct field tags.
|
||||||
|
// See golang.org/issue/13777 and golang.org/issue/14331.
|
||||||
|
if flag&obj.FmtShort == 0 && (!fmtbody || !t.Funarg) && t.Note != nil {
|
||||||
str += " " + strconv.Quote(*t.Note)
|
str += " " + strconv.Quote(*t.Note)
|
||||||
}
|
}
|
||||||
return str
|
return str
|
||||||
|
|
14
test/fixedbugs/issue14331.dir/a.go
Normal file
14
test/fixedbugs/issue14331.dir/a.go
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2016 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
|
||||||
|
|
||||||
|
var S struct {
|
||||||
|
Str string `tag`
|
||||||
|
}
|
||||||
|
|
||||||
|
func F() string {
|
||||||
|
v := S
|
||||||
|
return v.Str
|
||||||
|
}
|
11
test/fixedbugs/issue14331.dir/b.go
Normal file
11
test/fixedbugs/issue14331.dir/b.go
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
// Copyright 2016 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
|
||||||
|
|
||||||
|
import "./a"
|
||||||
|
|
||||||
|
func G() string {
|
||||||
|
return a.F()
|
||||||
|
}
|
9
test/fixedbugs/issue14331.go
Normal file
9
test/fixedbugs/issue14331.go
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// compiledir
|
||||||
|
|
||||||
|
// Copyright 2016 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.
|
||||||
|
|
||||||
|
// Inline function misses struct tags.
|
||||||
|
|
||||||
|
package ignored
|
Loading…
Reference in a new issue