go/types, types2: in SetUnderlying, set Named.fromRHS if not set yet

This is necessary for cycle detection over imported types whose
underlying types are set by importers with SetUnderlying.

Preparation for fixing issue #48962.

Change-Id: I3218cda7feb06440fdb8345c94bcaa5f7d64e94e
Reviewed-on: https://go-review.googlesource.com/c/go/+/379694
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Robert Griesemer 2022-01-19 18:10:40 -08:00
parent 9dfd458e64
commit 7520c080b4
2 changed files with 6 additions and 0 deletions

View File

@ -113,6 +113,9 @@ func (t *Named) SetUnderlying(underlying Type) {
panic("underlying type must not be *Named")
}
t.resolve(nil).underlying = underlying
if t.fromRHS == nil {
t.fromRHS = underlying // for cycle detection
}
}
// AddMethod adds method m unless it is already in the method list.

View File

@ -115,6 +115,9 @@ func (t *Named) SetUnderlying(underlying Type) {
panic("underlying type must not be *Named")
}
t.resolve(nil).underlying = underlying
if t.fromRHS == nil {
t.fromRHS = underlying // for cycle detection
}
}
// AddMethod adds method m unless it is already in the method list.