diff options
| author | Mateusz Poliwczak <mpoliwczak34@gmail.com> | 2026-03-27 18:09:23 +0100 |
|---|---|---|
| committer | Mateusz Poliwczak <mpoliwczak34@gmail.com> | 2026-03-30 07:27:52 -0700 |
| commit | 09031d907c720e38cdde6242c763d25c9f985327 (patch) | |
| tree | 3f2f72595f852207ced906893aa3a780a6f1e12d /src/cmd/compile/internal/devirtualize/devirtualize.go | |
| parent | acc2ce075982cea15636f018c421f96105049282 (diff) | |
| download | go-09031d907c720e38cdde6242c763d25c9f985327.tar.xz | |
cmd/compile/internal/devirtualize: use pointer identity for type comparison
Fixes #78404
Change-Id: I6adc1fb42ad6a3acce21333c6819d0796a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/760161
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/devirtualize/devirtualize.go')
| -rw-r--r-- | src/cmd/compile/internal/devirtualize/devirtualize.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/devirtualize/devirtualize.go b/src/cmd/compile/internal/devirtualize/devirtualize.go index 5f1da23654..59ddc2e536 100644 --- a/src/cmd/compile/internal/devirtualize/devirtualize.go +++ b/src/cmd/compile/internal/devirtualize/devirtualize.go @@ -293,9 +293,22 @@ func concreteType1(s *State, n ir.Node, seen map[*ir.Name]struct{}) (outT *types continue } } - if t == nil || (typ != nil && !types.Identical(typ, t)) { - return nil + if t == nil { + return nil // unknown concrete type } + + // Methods are only declared on named types, and each named type + // is represented by a unique [*types.Type], thus pointer comparison + // is fine here. + // + // The only scenario where [types.IdenticalStrict] could help here is with + // unnamed struct types that embed another type (e.g. foo = struct { Impl }{}). + // However, such patterns are uncommon and not worth the additional complexity + // in the devirtualizer. + if typ != nil && typ != t { + return nil // assigned with a different type + } + typ = t } |
