Source file src/cmd/compile/internal/types2/object.go

     1  // Copyright 2013 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package types2
     6  
     7  import (
     8  	"bytes"
     9  	"cmd/compile/internal/syntax"
    10  	"fmt"
    11  	"go/constant"
    12  	"strings"
    13  	"unicode"
    14  	"unicode/utf8"
    15  )
    16  
    17  // An Object is a named language entity.
    18  // An Object may be a constant ([Const]), type name ([TypeName]),
    19  // variable or struct field ([Var]), function or method ([Func]),
    20  // imported package ([PkgName]), label ([Label]),
    21  // built-in function ([Builtin]),
    22  // or the predeclared identifier 'nil' ([Nil]).
    23  //
    24  // The environment, which is structured as a tree of Scopes,
    25  // maps each name to the unique Object that it denotes.
    26  type Object interface {
    27  	Parent() *Scope  // scope in which this object is declared; nil for methods and struct fields
    28  	Pos() syntax.Pos // position of object identifier in declaration
    29  	Pkg() *Package   // package to which this object belongs; nil for labels and objects in the Universe scope
    30  	Name() string    // package local object name
    31  	Type() Type      // object type
    32  	Exported() bool  // reports whether the name starts with a capital letter
    33  	Id() string      // object name if exported, qualified name if not exported (see func Id)
    34  
    35  	// String returns a human-readable string of the object.
    36  	// Use [ObjectString] to control how package names are formatted in the string.
    37  	String() string
    38  
    39  	// order reflects a package-level object's source order: if object
    40  	// a is before object b in the source, then a.order() < b.order().
    41  	// order returns a value > 0 for package-level objects; it returns
    42  	// 0 for all other objects (including objects in file scopes).
    43  	order() uint32
    44  
    45  	// color returns the object's color.
    46  	color() color
    47  
    48  	// setType sets the type of the object.
    49  	setType(Type)
    50  
    51  	// setOrder sets the order number of the object. It must be > 0.
    52  	setOrder(uint32)
    53  
    54  	// setColor sets the object's color. It must not be white.
    55  	setColor(color color)
    56  
    57  	// setParent sets the parent scope of the object.
    58  	setParent(*Scope)
    59  
    60  	// sameId reports whether obj.Id() and Id(pkg, name) are the same.
    61  	// If foldCase is true, names are considered equal if they are equal with case folding
    62  	// and their packages are ignored (e.g., pkg1.m, pkg1.M, pkg2.m, and pkg2.M are all equal).
    63  	sameId(pkg *Package, name string, foldCase bool) bool
    64  
    65  	// scopePos returns the start position of the scope of this Object
    66  	scopePos() syntax.Pos
    67  
    68  	// setScopePos sets the start position of the scope for this Object.
    69  	setScopePos(pos syntax.Pos)
    70  }
    71  
    72  func isExported(name string) bool {
    73  	ch, _ := utf8.DecodeRuneInString(name)
    74  	return unicode.IsUpper(ch)
    75  }
    76  
    77  // Id returns name if it is exported, otherwise it
    78  // returns the name qualified with the package path.
    79  func Id(pkg *Package, name string) string {
    80  	if isExported(name) {
    81  		return name
    82  	}
    83  	// unexported names need the package path for differentiation
    84  	// (if there's no package, make sure we don't start with '.'
    85  	// as that may change the order of methods between a setup
    86  	// inside a package and outside a package - which breaks some
    87  	// tests)
    88  	path := "_"
    89  	// pkg is nil for objects in Universe scope and possibly types
    90  	// introduced via Eval (see also comment in object.sameId)
    91  	if pkg != nil && pkg.path != "" {
    92  		path = pkg.path
    93  	}
    94  	return path + "." + name
    95  }
    96  
    97  // An object implements the common parts of an Object.
    98  type object struct {
    99  	parent    *Scope
   100  	pos       syntax.Pos
   101  	pkg       *Package
   102  	name      string
   103  	typ       Type
   104  	order_    uint32
   105  	color_    color
   106  	scopePos_ syntax.Pos
   107  }
   108  
   109  // color encodes the color of an object (see Checker.objDecl for details).
   110  type color uint32
   111  
   112  // An object may be painted in one of three colors.
   113  // Color values other than white or black are considered grey.
   114  const (
   115  	white color = iota
   116  	black
   117  	grey // must be > white and black
   118  )
   119  
   120  func (c color) String() string {
   121  	switch c {
   122  	case white:
   123  		return "white"
   124  	case black:
   125  		return "black"
   126  	default:
   127  		return "grey"
   128  	}
   129  }
   130  
   131  // colorFor returns the (initial) color for an object depending on
   132  // whether its type t is known or not.
   133  func colorFor(t Type) color {
   134  	if t != nil {
   135  		return black
   136  	}
   137  	return white
   138  }
   139  
   140  // Parent returns the scope in which the object is declared.
   141  // The result is nil for methods and struct fields.
   142  func (obj *object) Parent() *Scope { return obj.parent }
   143  
   144  // Pos returns the declaration position of the object's identifier.
   145  func (obj *object) Pos() syntax.Pos { return obj.pos }
   146  
   147  // Pkg returns the package to which the object belongs.
   148  // The result is nil for labels and objects in the Universe scope.
   149  func (obj *object) Pkg() *Package { return obj.pkg }
   150  
   151  // Name returns the object's (package-local, unqualified) name.
   152  func (obj *object) Name() string { return obj.name }
   153  
   154  // Type returns the object's type.
   155  func (obj *object) Type() Type { return obj.typ }
   156  
   157  // Exported reports whether the object is exported (starts with a capital letter).
   158  // It doesn't take into account whether the object is in a local (function) scope
   159  // or not.
   160  func (obj *object) Exported() bool { return isExported(obj.name) }
   161  
   162  // Id is a wrapper for Id(obj.Pkg(), obj.Name()).
   163  func (obj *object) Id() string { return Id(obj.pkg, obj.name) }
   164  
   165  func (obj *object) String() string       { panic("abstract") }
   166  func (obj *object) order() uint32        { return obj.order_ }
   167  func (obj *object) color() color         { return obj.color_ }
   168  func (obj *object) scopePos() syntax.Pos { return obj.scopePos_ }
   169  
   170  func (obj *object) setParent(parent *Scope)    { obj.parent = parent }
   171  func (obj *object) setType(typ Type)           { obj.typ = typ }
   172  func (obj *object) setOrder(order uint32)      { assert(order > 0); obj.order_ = order }
   173  func (obj *object) setColor(color color)       { assert(color != white); obj.color_ = color }
   174  func (obj *object) setScopePos(pos syntax.Pos) { obj.scopePos_ = pos }
   175  
   176  func (obj *object) sameId(pkg *Package, name string, foldCase bool) bool {
   177  	// If we don't care about capitalization, we also ignore packages.
   178  	if foldCase && strings.EqualFold(obj.name, name) {
   179  		return true
   180  	}
   181  	// spec:
   182  	// "Two identifiers are different if they are spelled differently,
   183  	// or if they appear in different packages and are not exported.
   184  	// Otherwise, they are the same."
   185  	if obj.name != name {
   186  		return false
   187  	}
   188  	// obj.Name == name
   189  	if obj.Exported() {
   190  		return true
   191  	}
   192  	// not exported, so packages must be the same
   193  	return samePkg(obj.pkg, pkg)
   194  }
   195  
   196  // cmp reports whether object a is ordered before object b.
   197  // cmp returns:
   198  //
   199  //	-1 if a is before b
   200  //	 0 if a is equivalent to b
   201  //	+1 if a is behind b
   202  //
   203  // Objects are ordered nil before non-nil, exported before
   204  // non-exported, then by name, and finally (for non-exported
   205  // functions) by package path.
   206  func (a *object) cmp(b *object) int {
   207  	if a == b {
   208  		return 0
   209  	}
   210  
   211  	// Nil before non-nil.
   212  	if a == nil {
   213  		return -1
   214  	}
   215  	if b == nil {
   216  		return +1
   217  	}
   218  
   219  	// Exported functions before non-exported.
   220  	ea := isExported(a.name)
   221  	eb := isExported(b.name)
   222  	if ea != eb {
   223  		if ea {
   224  			return -1
   225  		}
   226  		return +1
   227  	}
   228  
   229  	// Order by name and then (for non-exported names) by package.
   230  	if a.name != b.name {
   231  		return strings.Compare(a.name, b.name)
   232  	}
   233  	if !ea {
   234  		return strings.Compare(a.pkg.path, b.pkg.path)
   235  	}
   236  
   237  	return 0
   238  }
   239  
   240  // A PkgName represents an imported Go package.
   241  // PkgNames don't have a type.
   242  type PkgName struct {
   243  	object
   244  	imported *Package
   245  	used     bool // set if the package was used
   246  }
   247  
   248  // NewPkgName returns a new PkgName object representing an imported package.
   249  // The remaining arguments set the attributes found with all Objects.
   250  func NewPkgName(pos syntax.Pos, pkg *Package, name string, imported *Package) *PkgName {
   251  	return &PkgName{object{nil, pos, pkg, name, Typ[Invalid], 0, black, nopos}, imported, false}
   252  }
   253  
   254  // Imported returns the package that was imported.
   255  // It is distinct from Pkg(), which is the package containing the import statement.
   256  func (obj *PkgName) Imported() *Package { return obj.imported }
   257  
   258  // A Const represents a declared constant.
   259  type Const struct {
   260  	object
   261  	val constant.Value
   262  }
   263  
   264  // NewConst returns a new constant with value val.
   265  // The remaining arguments set the attributes found with all Objects.
   266  func NewConst(pos syntax.Pos, pkg *Package, name string, typ Type, val constant.Value) *Const {
   267  	return &Const{object{nil, pos, pkg, name, typ, 0, colorFor(typ), nopos}, val}
   268  }
   269  
   270  // Val returns the constant's value.
   271  func (obj *Const) Val() constant.Value { return obj.val }
   272  
   273  func (*Const) isDependency() {} // a constant may be a dependency of an initialization expression
   274  
   275  // A TypeName is an [Object] that represents a type with a name:
   276  // a defined type ([Named]),
   277  // an alias type ([Alias]),
   278  // a type parameter ([TypeParam]),
   279  // or a predeclared type such as int or error.
   280  type TypeName struct {
   281  	object
   282  }
   283  
   284  // NewTypeName returns a new type name denoting the given typ.
   285  // The remaining arguments set the attributes found with all Objects.
   286  //
   287  // The typ argument may be a defined (Named) type or an alias type.
   288  // It may also be nil such that the returned TypeName can be used as
   289  // argument for NewNamed, which will set the TypeName's type as a side-
   290  // effect.
   291  func NewTypeName(pos syntax.Pos, pkg *Package, name string, typ Type) *TypeName {
   292  	return &TypeName{object{nil, pos, pkg, name, typ, 0, colorFor(typ), nopos}}
   293  }
   294  
   295  // NewTypeNameLazy returns a new defined type like NewTypeName, but it
   296  // lazily calls resolve to finish constructing the Named object.
   297  func NewTypeNameLazy(pos syntax.Pos, pkg *Package, name string, load func(named *Named) (tparams []*TypeParam, underlying Type, methods []*Func)) *TypeName {
   298  	obj := NewTypeName(pos, pkg, name, nil)
   299  	NewNamed(obj, nil, nil).loader = load
   300  	return obj
   301  }
   302  
   303  // IsAlias reports whether obj is an alias name for a type.
   304  func (obj *TypeName) IsAlias() bool {
   305  	switch t := obj.typ.(type) {
   306  	case nil:
   307  		return false
   308  	// case *Alias:
   309  	//	handled by default case
   310  	case *Basic:
   311  		// unsafe.Pointer is not an alias.
   312  		if obj.pkg == Unsafe {
   313  			return false
   314  		}
   315  		// Any user-defined type name for a basic type is an alias for a
   316  		// basic type (because basic types are pre-declared in the Universe
   317  		// scope, outside any package scope), and so is any type name with
   318  		// a different name than the name of the basic type it refers to.
   319  		// Additionally, we need to look for "byte" and "rune" because they
   320  		// are aliases but have the same names (for better error messages).
   321  		return obj.pkg != nil || t.name != obj.name || t == universeByte || t == universeRune
   322  	case *Named:
   323  		return obj != t.obj
   324  	case *TypeParam:
   325  		return obj != t.obj
   326  	default:
   327  		return true
   328  	}
   329  }
   330  
   331  // A Variable represents a declared variable (including function parameters and results, and struct fields).
   332  type Var struct {
   333  	object
   334  	embedded bool // if set, the variable is an embedded struct field, and name is the type name
   335  	isField  bool // var is struct field
   336  	used     bool // set if the variable was used
   337  	origin   *Var // if non-nil, the Var from which this one was instantiated
   338  }
   339  
   340  // NewVar returns a new variable.
   341  // The arguments set the attributes found with all Objects.
   342  func NewVar(pos syntax.Pos, pkg *Package, name string, typ Type) *Var {
   343  	return &Var{object: object{nil, pos, pkg, name, typ, 0, colorFor(typ), nopos}}
   344  }
   345  
   346  // NewParam returns a new variable representing a function parameter.
   347  func NewParam(pos syntax.Pos, pkg *Package, name string, typ Type) *Var {
   348  	return &Var{object: object{nil, pos, pkg, name, typ, 0, colorFor(typ), nopos}, used: true} // parameters are always 'used'
   349  }
   350  
   351  // NewField returns a new variable representing a struct field.
   352  // For embedded fields, the name is the unqualified type name
   353  // under which the field is accessible.
   354  func NewField(pos syntax.Pos, pkg *Package, name string, typ Type, embedded bool) *Var {
   355  	return &Var{object: object{nil, pos, pkg, name, typ, 0, colorFor(typ), nopos}, embedded: embedded, isField: true}
   356  }
   357  
   358  // Anonymous reports whether the variable is an embedded field.
   359  // Same as Embedded; only present for backward-compatibility.
   360  func (obj *Var) Anonymous() bool { return obj.embedded }
   361  
   362  // Embedded reports whether the variable is an embedded field.
   363  func (obj *Var) Embedded() bool { return obj.embedded }
   364  
   365  // IsField reports whether the variable is a struct field.
   366  func (obj *Var) IsField() bool { return obj.isField }
   367  
   368  // Origin returns the canonical Var for its receiver, i.e. the Var object
   369  // recorded in Info.Defs.
   370  //
   371  // For synthetic Vars created during instantiation (such as struct fields or
   372  // function parameters that depend on type arguments), this will be the
   373  // corresponding Var on the generic (uninstantiated) type. For all other Vars
   374  // Origin returns the receiver.
   375  func (obj *Var) Origin() *Var {
   376  	if obj.origin != nil {
   377  		return obj.origin
   378  	}
   379  	return obj
   380  }
   381  
   382  func (*Var) isDependency() {} // a variable may be a dependency of an initialization expression
   383  
   384  // A Func represents a declared function, concrete method, or abstract
   385  // (interface) method. Its Type() is always a *Signature.
   386  // An abstract method may belong to many interfaces due to embedding.
   387  type Func struct {
   388  	object
   389  	hasPtrRecv_ bool  // only valid for methods that don't have a type yet; use hasPtrRecv() to read
   390  	origin      *Func // if non-nil, the Func from which this one was instantiated
   391  }
   392  
   393  // NewFunc returns a new function with the given signature, representing
   394  // the function's type.
   395  func NewFunc(pos syntax.Pos, pkg *Package, name string, sig *Signature) *Func {
   396  	var typ Type
   397  	if sig != nil {
   398  		typ = sig
   399  	} else {
   400  		// Don't store a (typed) nil *Signature.
   401  		// We can't simply replace it with new(Signature) either,
   402  		// as this would violate object.{Type,color} invariants.
   403  		// TODO(adonovan): propose to disallow NewFunc with nil *Signature.
   404  	}
   405  	return &Func{object{nil, pos, pkg, name, typ, 0, colorFor(typ), nopos}, false, nil}
   406  }
   407  
   408  // Signature returns the signature (type) of the function or method.
   409  func (obj *Func) Signature() *Signature {
   410  	if obj.typ != nil {
   411  		return obj.typ.(*Signature) // normal case
   412  	}
   413  	// No signature: Signature was called either:
   414  	// - within go/types, before a FuncDecl's initially
   415  	//   nil Func.Type was lazily populated, indicating
   416  	//   a types bug; or
   417  	// - by a client after NewFunc(..., nil),
   418  	//   which is arguably a client bug, but we need a
   419  	//   proposal to tighten NewFunc's precondition.
   420  	// For now, return a trivial signature.
   421  	return new(Signature)
   422  }
   423  
   424  // FullName returns the package- or receiver-type-qualified name of
   425  // function or method obj.
   426  func (obj *Func) FullName() string {
   427  	var buf bytes.Buffer
   428  	writeFuncName(&buf, obj, nil)
   429  	return buf.String()
   430  }
   431  
   432  // Scope returns the scope of the function's body block.
   433  // The result is nil for imported or instantiated functions and methods
   434  // (but there is also no mechanism to get to an instantiated function).
   435  func (obj *Func) Scope() *Scope { return obj.typ.(*Signature).scope }
   436  
   437  // Origin returns the canonical Func for its receiver, i.e. the Func object
   438  // recorded in Info.Defs.
   439  //
   440  // For synthetic functions created during instantiation (such as methods on an
   441  // instantiated Named type or interface methods that depend on type arguments),
   442  // this will be the corresponding Func on the generic (uninstantiated) type.
   443  // For all other Funcs Origin returns the receiver.
   444  func (obj *Func) Origin() *Func {
   445  	if obj.origin != nil {
   446  		return obj.origin
   447  	}
   448  	return obj
   449  }
   450  
   451  // Pkg returns the package to which the function belongs.
   452  //
   453  // The result is nil for methods of types in the Universe scope,
   454  // like method Error of the error built-in interface type.
   455  func (obj *Func) Pkg() *Package { return obj.object.Pkg() }
   456  
   457  // hasPtrRecv reports whether the receiver is of the form *T for the given method obj.
   458  func (obj *Func) hasPtrRecv() bool {
   459  	// If a method's receiver type is set, use that as the source of truth for the receiver.
   460  	// Caution: Checker.funcDecl (decl.go) marks a function by setting its type to an empty
   461  	// signature. We may reach here before the signature is fully set up: we must explicitly
   462  	// check if the receiver is set (we cannot just look for non-nil obj.typ).
   463  	if sig, _ := obj.typ.(*Signature); sig != nil && sig.recv != nil {
   464  		_, isPtr := deref(sig.recv.typ)
   465  		return isPtr
   466  	}
   467  
   468  	// If a method's type is not set it may be a method/function that is:
   469  	// 1) client-supplied (via NewFunc with no signature), or
   470  	// 2) internally created but not yet type-checked.
   471  	// For case 1) we can't do anything; the client must know what they are doing.
   472  	// For case 2) we can use the information gathered by the resolver.
   473  	return obj.hasPtrRecv_
   474  }
   475  
   476  func (*Func) isDependency() {} // a function may be a dependency of an initialization expression
   477  
   478  // A Label represents a declared label.
   479  // Labels don't have a type.
   480  type Label struct {
   481  	object
   482  	used bool // set if the label was used
   483  }
   484  
   485  // NewLabel returns a new label.
   486  func NewLabel(pos syntax.Pos, pkg *Package, name string) *Label {
   487  	return &Label{object{pos: pos, pkg: pkg, name: name, typ: Typ[Invalid], color_: black}, false}
   488  }
   489  
   490  // A Builtin represents a built-in function.
   491  // Builtins don't have a valid type.
   492  type Builtin struct {
   493  	object
   494  	id builtinId
   495  }
   496  
   497  func newBuiltin(id builtinId) *Builtin {
   498  	return &Builtin{object{name: predeclaredFuncs[id].name, typ: Typ[Invalid], color_: black}, id}
   499  }
   500  
   501  // Nil represents the predeclared value nil.
   502  type Nil struct {
   503  	object
   504  }
   505  
   506  func writeObject(buf *bytes.Buffer, obj Object, qf Qualifier) {
   507  	var tname *TypeName
   508  	typ := obj.Type()
   509  
   510  	switch obj := obj.(type) {
   511  	case *PkgName:
   512  		fmt.Fprintf(buf, "package %s", obj.Name())
   513  		if path := obj.imported.path; path != "" && path != obj.name {
   514  			fmt.Fprintf(buf, " (%q)", path)
   515  		}
   516  		return
   517  
   518  	case *Const:
   519  		buf.WriteString("const")
   520  
   521  	case *TypeName:
   522  		tname = obj
   523  		buf.WriteString("type")
   524  		if isTypeParam(typ) {
   525  			buf.WriteString(" parameter")
   526  		}
   527  
   528  	case *Var:
   529  		if obj.isField {
   530  			buf.WriteString("field")
   531  		} else {
   532  			buf.WriteString("var")
   533  		}
   534  
   535  	case *Func:
   536  		buf.WriteString("func ")
   537  		writeFuncName(buf, obj, qf)
   538  		if typ != nil {
   539  			WriteSignature(buf, typ.(*Signature), qf)
   540  		}
   541  		return
   542  
   543  	case *Label:
   544  		buf.WriteString("label")
   545  		typ = nil
   546  
   547  	case *Builtin:
   548  		buf.WriteString("builtin")
   549  		typ = nil
   550  
   551  	case *Nil:
   552  		buf.WriteString("nil")
   553  		return
   554  
   555  	default:
   556  		panic(fmt.Sprintf("writeObject(%T)", obj))
   557  	}
   558  
   559  	buf.WriteByte(' ')
   560  
   561  	// For package-level objects, qualify the name.
   562  	if obj.Pkg() != nil && obj.Pkg().scope.Lookup(obj.Name()) == obj {
   563  		buf.WriteString(packagePrefix(obj.Pkg(), qf))
   564  	}
   565  	buf.WriteString(obj.Name())
   566  
   567  	if typ == nil {
   568  		return
   569  	}
   570  
   571  	if tname != nil {
   572  		switch t := typ.(type) {
   573  		case *Basic:
   574  			// Don't print anything more for basic types since there's
   575  			// no more information.
   576  			return
   577  		case genericType:
   578  			if t.TypeParams().Len() > 0 {
   579  				newTypeWriter(buf, qf).tParamList(t.TypeParams().list())
   580  			}
   581  		}
   582  		if tname.IsAlias() {
   583  			buf.WriteString(" =")
   584  			if alias, ok := typ.(*Alias); ok { // materialized? (gotypesalias=1)
   585  				typ = alias.fromRHS
   586  			}
   587  		} else if t, _ := typ.(*TypeParam); t != nil {
   588  			typ = t.bound
   589  		} else {
   590  			// TODO(gri) should this be fromRHS for *Named?
   591  			// (See discussion in #66559.)
   592  			typ = under(typ)
   593  		}
   594  	}
   595  
   596  	// Special handling for any: because WriteType will format 'any' as 'any',
   597  	// resulting in the object string `type any = any` rather than `type any =
   598  	// interface{}`. To avoid this, swap in a different empty interface.
   599  	if obj.Name() == "any" && obj.Parent() == Universe {
   600  		assert(Identical(typ, &emptyInterface))
   601  		typ = &emptyInterface
   602  	}
   603  
   604  	buf.WriteByte(' ')
   605  	WriteType(buf, typ, qf)
   606  }
   607  
   608  func packagePrefix(pkg *Package, qf Qualifier) string {
   609  	if pkg == nil {
   610  		return ""
   611  	}
   612  	var s string
   613  	if qf != nil {
   614  		s = qf(pkg)
   615  	} else {
   616  		s = pkg.Path()
   617  	}
   618  	if s != "" {
   619  		s += "."
   620  	}
   621  	return s
   622  }
   623  
   624  // ObjectString returns the string form of obj.
   625  // The Qualifier controls the printing of
   626  // package-level objects, and may be nil.
   627  func ObjectString(obj Object, qf Qualifier) string {
   628  	var buf bytes.Buffer
   629  	writeObject(&buf, obj, qf)
   630  	return buf.String()
   631  }
   632  
   633  func (obj *PkgName) String() string  { return ObjectString(obj, nil) }
   634  func (obj *Const) String() string    { return ObjectString(obj, nil) }
   635  func (obj *TypeName) String() string { return ObjectString(obj, nil) }
   636  func (obj *Var) String() string      { return ObjectString(obj, nil) }
   637  func (obj *Func) String() string     { return ObjectString(obj, nil) }
   638  func (obj *Label) String() string    { return ObjectString(obj, nil) }
   639  func (obj *Builtin) String() string  { return ObjectString(obj, nil) }
   640  func (obj *Nil) String() string      { return ObjectString(obj, nil) }
   641  
   642  func writeFuncName(buf *bytes.Buffer, f *Func, qf Qualifier) {
   643  	if f.typ != nil {
   644  		sig := f.typ.(*Signature)
   645  		if recv := sig.Recv(); recv != nil {
   646  			buf.WriteByte('(')
   647  			if _, ok := recv.Type().(*Interface); ok {
   648  				// gcimporter creates abstract methods of
   649  				// named interfaces using the interface type
   650  				// (not the named type) as the receiver.
   651  				// Don't print it in full.
   652  				buf.WriteString("interface")
   653  			} else {
   654  				WriteType(buf, recv.Type(), qf)
   655  			}
   656  			buf.WriteByte(')')
   657  			buf.WriteByte('.')
   658  		} else if f.pkg != nil {
   659  			buf.WriteString(packagePrefix(f.pkg, qf))
   660  		}
   661  	}
   662  	buf.WriteString(f.name)
   663  }
   664  

View as plain text