diff options
author | Robert Griesemer <gri@golang.org> | 2024-01-24 12:42:11 -0800 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2024-01-26 14:04:26 +0000 |
commit | 8e02e7b26af46a1d113057ac49ad440a39a45d58 (patch) | |
tree | bf9a31128347256bcfa152b452b9c29cf5220035 /src/cmd/compile/internal/types2/predicates.go | |
parent | d278d5bbdddd0e976c272d1dd3ecc41eeb37daf9 (diff) | |
download | go-8e02e7b26af46a1d113057ac49ad440a39a45d58.tar.gz go-8e02e7b26af46a1d113057ac49ad440a39a45d58.zip |
go/types, types2: use existing case-insensitive lookup (remove TODO)
Rather than implementing a new, less complete mechanism to check
if a selector exists with different capitalization, use the
existing mechanism in lookupFieldOrMethodImpl by making it
available for internal use.
Pass foldCase parameter all the way trough to Object.sameId and
thus make it consistently available where Object.sameId is used.
From sameId, factor out samePkg functionality into stand-alone
predicate.
Do better case distinction when reporting an error for an undefined
selector expression.
Cleanup.
Change-Id: I7be3cecb4976a4dce3264c7e0c49a320c87101e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/558315
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/types2/predicates.go')
-rw-r--r-- | src/cmd/compile/internal/types2/predicates.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/types2/predicates.go b/src/cmd/compile/internal/types2/predicates.go index 7a096e3d97..bb2b53a942 100644 --- a/src/cmd/compile/internal/types2/predicates.go +++ b/src/cmd/compile/internal/types2/predicates.go @@ -205,6 +205,16 @@ func hasNil(t Type) bool { return false } +// samePkg reports whether packages a and b are the same. +func samePkg(a, b *Package) bool { + // package is nil for objects in universe scope + if a == nil || b == nil { + return a == b + } + // a != nil && b != nil + return a.path == b.path +} + // An ifacePair is a node in a stack of interface type pairs compared for identity. type ifacePair struct { x, y *Interface @@ -269,7 +279,7 @@ func (c *comparer) identical(x, y Type, p *ifacePair) bool { g := y.fields[i] if f.embedded != g.embedded || !c.ignoreTags && x.Tag(i) != y.Tag(i) || - !f.sameId(g.pkg, g.name) || + !f.sameId(g.pkg, g.name, false) || !c.identical(f.typ, g.typ, p) { return false } |