go/ssa: fix bug causing (manual) go/pointer stdlib test to crash.
The needMethods cache logic was wrong: it would treat any previous call as a cache hit, even if 'skip' was true for that call. As a result it could fail to generate methods for some 'skip' types, i.e. anonymous structs. LGTM=gri R=gri CC=golang-codereviews https://golang.org/cl/144750043
This commit is contained in:
parent
66176e290c
commit
85a9565822
|
@ -54,7 +54,7 @@ func TestStdlib(t *testing.T) {
|
||||||
prog.BuildAll()
|
prog.BuildAll()
|
||||||
|
|
||||||
numPkgs := len(prog.AllPackages())
|
numPkgs := len(prog.AllPackages())
|
||||||
if want := 140; numPkgs < want {
|
if want := 240; numPkgs < want {
|
||||||
t.Errorf("Loaded only %d packages, want at least %d", numPkgs, want)
|
t.Errorf("Loaded only %d packages, want at least %d", numPkgs, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2307,9 +2307,13 @@ func (p *Package) needMethodsOf(T types.Type) {
|
||||||
// Recursive case: skip => don't call makeMethods(T).
|
// Recursive case: skip => don't call makeMethods(T).
|
||||||
func (p *Package) needMethods(T types.Type, skip bool) {
|
func (p *Package) needMethods(T types.Type, skip bool) {
|
||||||
// Each package maintains its own set of types it has visited.
|
// Each package maintains its own set of types it has visited.
|
||||||
if p.needRTTI.Set(T, true) != nil {
|
if prevSkip, ok := p.needRTTI.At(T).(bool); ok {
|
||||||
return // already seen
|
// needMethods(T) was previously called
|
||||||
|
if !prevSkip || skip {
|
||||||
|
return // already seen, with same or false 'skip' value
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
p.needRTTI.Set(T, skip)
|
||||||
|
|
||||||
// Prune the recursion if we find a named or *named type
|
// Prune the recursion if we find a named or *named type
|
||||||
// belonging to another package.
|
// belonging to another package.
|
||||||
|
|
Loading…
Reference in New Issue