compiler: refactor method names

This commit includes two changes:

  * It makes unexported interface methods package-private, so that it's
    not possible to type-assert on an unexported method in a different
    package.
  * It makes the globals used to identify interface methods defined
    globals, so that they can (eventually) be left in the program for an
    eventual non-LTO build mode.
This commit is contained in:
Ayke van Laethem
2021-06-04 14:43:25 +02:00
committed by Ron Evans
parent 52d640967b
commit f2e8d7112c
8 changed files with 47 additions and 32 deletions
+7 -3
View File
@@ -54,10 +54,14 @@ type signatureInfo struct {
// methodName takes a method name like "func String()" and returns only the
// name, which is "String" in this case.
func (s *signatureInfo) methodName() string {
if !strings.HasPrefix(s.name, "func ") {
panic("signature must start with \"func \"")
var methodName string
if strings.HasPrefix(s.name, "reflect/methods.") {
methodName = s.name[len("reflect/methods."):]
} else if idx := strings.LastIndex(s.name, ".$methods."); idx >= 0 {
methodName = s.name[idx+len(".$methods."):]
} else {
panic("could not find method name")
}
methodName := s.name[len("func "):]
if openingParen := strings.IndexByte(methodName, '('); openingParen < 0 {
panic("no opening paren in signature name")
} else {