1
0
mirror of https://github.com/golang/go synced 2024-11-14 14:50:23 -07:00
go/test/fixedbugs/issue24547.go
Matthew Dempsky 7b177b1a03 cmd/compile: fix method set computation for shadowed methods
In expandmeth, we call expand1/expand0 to build a list of all
candidate methods to promote, and then we use dotpath to prune down
which names actually resolve to a promoted method and how.

However, previously we still computed "followsptr" based on the
expand1/expand0 traversal (which is depth-first), rather than
dotpath (which is breadth-first). The result is that we could
sometimes end up miscomputing whether a particular promoted method
involves a pointer traversal, which could result in bad code
generation for method trampolines.

Fixes #24547.

Change-Id: I57dc014466d81c165b05d78b98610dc3765b7a90
Reviewed-on: https://go-review.googlesource.com/102618
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-03-27 18:56:36 +00:00

47 lines
757 B
Go

// run
// 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.
// When computing method sets with shadowed methods, make sure we
// compute whether a method promotion involved a pointer traversal
// based on the promoted method, not the shadowed method.
package main
import (
"bytes"
"fmt"
)
type mystruct struct {
f int
}
func (t mystruct) String() string {
return "FAIL"
}
func main() {
type deep struct {
mystruct
}
s := struct {
deep
*bytes.Buffer
}{
deep{},
bytes.NewBufferString("ok"),
}
if got := s.String(); got != "ok" {
panic(got)
}
var i fmt.Stringer = s
if got := i.String(); got != "ok" {
panic(got)
}
}