Does it use for generics constraints only? As described at https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#comparable-types-in-constraints . If so the type comparison and this interface is two unrelated things?
On Friday, March 12, 2021 at 11:42:07 AM UTC+8 messi...@gmail.com wrote: > Hi, > > I'm reading the new typechecker source code of go compiler(under directory > cmd/compile/internal/types2), during the initialization process, > universe.go registers an implicit interface "comparable" inside function > defPredeclaredComparable > <https://github.com/golang/go/blob/e8b82789cda6c9d9e3dfc9a652b4d7a823b834f2/src/cmd/compile/internal/types2/universe.go#L199>, > > I know it's supposed to be used for type comparison > <https://golang.org/ref/spec#Comparison_operators>but failed to find > where and how this interface and related method "==" is used. > > In predicates.go > <https://github.com/golang/go/blob/e8b82789cda6c9d9e3dfc9a652b4d7a823b834f2/src/cmd/compile/internal/types2/predicates.go#L86> > there's > a function 'Comparable" to check whether a type is comparable or not, but > seems there's nothing to do with the interface. > > And I don't understand the lookup logic for method "==" in type.go > <https://github.com/golang/go/blob/e8b82789cda6c9d9e3dfc9a652b4d7a823b834f2/src/cmd/compile/internal/types2/type.go#L465> > neither, > how could an Interface type have method named "=="? > > I searched a lot from the code base but failed to find the answer, could > anybody kindly give me some clue? > > Thanks a lot :-) > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/50661f0e-289e-43f3-a9d7-a42feb77f7fbn%40googlegroups.com.