aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2022-01-19 18:10:40 -0800
committerRobert Griesemer <gri@golang.org>2022-01-24 21:27:25 +0000
commit7520c080b45e9493b289d622aed8d8a0da528089 (patch)
treed8ec8578ee637cd01fb0627083d279efb53859ad
parent9dfd458e64a2d3fa92fb7b5da393163151f99cf2 (diff)
downloadgo-7520c080b45e9493b289d622aed8d8a0da528089.tar.gz
go-7520c080b45e9493b289d622aed8d8a0da528089.zip
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>
-rw-r--r--src/cmd/compile/internal/types2/named.go3
-rw-r--r--src/go/types/named.go3
2 files changed, 6 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/types2/named.go b/src/cmd/compile/internal/types2/named.go
index 834a25066b..3ba53052d7 100644
--- a/src/cmd/compile/internal/types2/named.go
+++ b/src/cmd/compile/internal/types2/named.go
@@ -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.
diff --git a/src/go/types/named.go b/src/go/types/named.go
index 6c77146485..f0c22d29e3 100644
--- a/src/go/types/named.go
+++ b/src/go/types/named.go
@@ -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.