]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: in SetUnderlying, set Named.fromRHS if not set yet
authorRobert Griesemer <gri@golang.org>
Thu, 20 Jan 2022 02:10:40 +0000 (18:10 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 24 Jan 2022 21:27:25 +0000 (21:27 +0000)
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>

src/cmd/compile/internal/types2/named.go
src/go/types/named.go

index 834a25066b87b7d23cc9b5f8f6a74473360c05ac..3ba53052d79adb913da0e7b5e3ba9183d30fba14 100644 (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.
index 6c77146485a9a5e29d8d1058cb5c8ec43d935b0c..f0c22d29e313d3a4649faae02eaa9b94f9192cbe 100644 (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.