aboutsummaryrefslogtreecommitdiff
path: root/src/go/types/typestring.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/go/types/typestring.go')
-rw-r--r--src/go/types/typestring.go55
1 files changed, 19 insertions, 36 deletions
diff --git a/src/go/types/typestring.go b/src/go/types/typestring.go
index 64bbb33505..fe27f0f276 100644
--- a/src/go/types/typestring.go
+++ b/src/go/types/typestring.go
@@ -9,6 +9,7 @@ package types
import (
"bytes"
"fmt"
+ "go/token"
"unicode/utf8"
)
@@ -98,9 +99,15 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) {
buf.WriteString("<nil>")
case *Basic:
- if t.kind == UnsafePointer {
- buf.WriteString("unsafe.")
+ // exported basic types go into package unsafe
+ // (currently this is just unsafe.Pointer)
+ if token.IsExported(t.name) {
+ if obj, _ := Unsafe.scope.Lookup(t.name).(*TypeName); obj != nil {
+ writeTypeName(buf, obj, qf)
+ break
+ }
}
+
if gcCompatibilityMode {
// forget the alias names
switch t.kind {
@@ -126,19 +133,14 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) {
if i > 0 {
buf.WriteString("; ")
}
- buf.WriteString(f.name)
- if f.embedded {
- // emphasize that the embedded field's name
- // doesn't match the field's type name
- if f.name != embeddedFieldName(f.typ) {
- buf.WriteString(" /* = ")
- writeType(buf, f.typ, qf, visited)
- buf.WriteString(" */")
- }
- } else {
+ // This doesn't do the right thing for embedded type
+ // aliases where we should print the alias name, not
+ // the aliased type (see issue #44410).
+ if !f.embedded {
+ buf.WriteString(f.name)
buf.WriteByte(' ')
- writeType(buf, f.typ, qf, visited)
}
+ writeType(buf, f.typ, qf, visited)
if tag := t.Tag(i); tag != "" {
fmt.Fprintf(buf, " %q", tag)
}
@@ -156,7 +158,7 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) {
buf.WriteString("func")
writeSignature(buf, t, qf, visited)
- case *Sum:
+ case *_Sum:
for i, t := range t.types {
if i > 0 {
buf.WriteString(", ")
@@ -277,7 +279,7 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) {
writeTParamList(buf, t.tparams, qf, visited)
}
- case *TypeParam:
+ case *_TypeParam:
s := "?"
if t.obj != nil {
s = t.obj.name
@@ -319,7 +321,7 @@ func writeTParamList(buf *bytes.Buffer, list []*TypeName, qf Qualifier, visited
for i, p := range list {
// TODO(rFindley) support 'any' sugar here.
var b Type = &emptyInterface
- if t, _ := p.typ.(*TypeParam); t != nil && t.bound != nil {
+ if t, _ := p.typ.(*_TypeParam); t != nil && t.bound != nil {
b = t.bound
}
if i > 0 {
@@ -332,7 +334,7 @@ func writeTParamList(buf *bytes.Buffer, list []*TypeName, qf Qualifier, visited
}
prev = b
- if t, _ := p.typ.(*TypeParam); t != nil {
+ if t, _ := p.typ.(*_TypeParam); t != nil {
writeType(buf, t, qf, visited)
} else {
buf.WriteString(p.name)
@@ -424,25 +426,6 @@ func writeSignature(buf *bytes.Buffer, sig *Signature, qf Qualifier, visited []T
writeTuple(buf, sig.results, false, qf, visited)
}
-// embeddedFieldName returns an embedded field's name given its type.
-// The result is "" if the type doesn't have an embedded field name.
-func embeddedFieldName(typ Type) string {
- switch t := typ.(type) {
- case *Basic:
- return t.name
- case *Named:
- return t.obj.name
- case *Pointer:
- // *T is ok, but **T is not
- if _, ok := t.base.(*Pointer); !ok {
- return embeddedFieldName(t.base)
- }
- case *instance:
- return t.base.obj.name
- }
- return "" // not a (pointer to) a defined type
-}
-
// subscript returns the decimal (utf8) representation of x using subscript digits.
func subscript(x uint64) string {
const w = len("₀") // all digits 0...9 have the same utf8 width