Skip to content

Commit 9ff91b9

Browse files
committed
cmd/compile: only look for struct type when crawling inline body
CL 356254 fixed crawling of embeddable types during inline. However, we are too agressive, since when we call markEmbed for every type seen during inlining function body. That leads to false positive that for a non-embedded type, its unexported methods are also marked inline. Instead, we should only look at struct type that we seen during inlining function body, and calling markEmbed for all of its embedded fields. Fixes #49094 Change-Id: I6ef9a8bf1fc649ec6bf75e4883f6031ec8560ba1 Reviewed-on: https://go-review.googlesource.com/c/go/+/357232 Trust: Cuong Manh Le <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 23e57e5 commit 9ff91b9

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

src/cmd/compile/internal/typecheck/crawler.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,13 @@ func (p *crawler) markInlBody(n *ir.Name) {
217217
//
218218
// We generate the wrapper for "struct{ t }".M, and inline call
219219
// to "struct{ t }".M, which makes "t.M" reachable.
220-
p.markEmbed(t)
220+
if t.IsStruct() {
221+
for _, f := range t.FieldSlice() {
222+
if f.Embedded != 0 {
223+
p.markEmbed(f.Type)
224+
}
225+
}
226+
}
221227
}
222228
}
223229

test/fixedbugs/issue49094.dir/a.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package a
6+
7+
type A struct{}
8+
9+
func (a *A) f() bool {
10+
return true
11+
}

test/fixedbugs/issue49094.dir/b.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package b
6+
7+
import "./a"
8+
9+
func M(r *a.A) string {
10+
return ""
11+
}

test/fixedbugs/issue49094.dir/p.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package p
6+
7+
import (
8+
"./b"
9+
)
10+
11+
type S struct{}
12+
13+
func (S) M() {
14+
b.M(nil)
15+
}

test/fixedbugs/issue49094.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// compiledir
2+
3+
// Copyright 2021 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package ignored

0 commit comments

Comments
 (0)