mirror of
https://github.com/golang/go
synced 2024-11-26 07:17:59 -07:00
[dev.typeparams] cmd/compile/internal/types2: use same sort criteria for methods as compiler
Note: This invalidates the implementation of MethodSet further (it also has not been updated to accomodate for type parameters). But types2 doesn't make use of it. We should remove it. Change-Id: Ia2601bdd59b3f3ee0b72bc2512153c42bf5053b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/285994 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
2b95c28b18
commit
5347241b5e
@ -330,6 +330,36 @@ func (obj *Func) FullName() string {
|
||||
// Scope returns the scope of the function's body block.
|
||||
func (obj *Func) Scope() *Scope { return obj.typ.(*Signature).scope }
|
||||
|
||||
// Less reports whether function a is ordered before function b.
|
||||
//
|
||||
// Functions are ordered exported before non-exported, then by name,
|
||||
// and finally (for non-exported functions) by package path.
|
||||
//
|
||||
// TODO(gri) The compiler also sorts by package height before package
|
||||
// path for non-exported names.
|
||||
func (a *Func) less(b *Func) bool {
|
||||
if a == b {
|
||||
return false
|
||||
}
|
||||
|
||||
// Exported functions before non-exported.
|
||||
ea := isExported(a.name)
|
||||
eb := isExported(b.name)
|
||||
if ea != eb {
|
||||
return ea
|
||||
}
|
||||
|
||||
// Order by name and then (for non-exported names) by package.
|
||||
if a.name != b.name {
|
||||
return a.name < b.name
|
||||
}
|
||||
if !ea {
|
||||
return a.pkg.path < b.pkg.path
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (*Func) isDependency() {} // a function may be a dependency of an initialization expression
|
||||
|
||||
// A Label represents a declared label.
|
||||
|
@ -1064,7 +1064,7 @@ func assertSortedMethods(list []*Func) {
|
||||
type byUniqueMethodName []*Func
|
||||
|
||||
func (a byUniqueMethodName) Len() int { return len(a) }
|
||||
func (a byUniqueMethodName) Less(i, j int) bool { return a[i].Id() < a[j].Id() }
|
||||
func (a byUniqueMethodName) Less(i, j int) bool { return a[i].less(a[j]) }
|
||||
func (a byUniqueMethodName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
|
||||
func (check *Checker) tag(t *syntax.BasicLit) string {
|
||||
|
Loading…
Reference in New Issue
Block a user