]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/compile/internal/types2/typestring.go
go/types, types2: introduce _Alias type node
[gostls13.git] / src / cmd / compile / internal / types2 / typestring.go
index ecabe013e39fba9170a19e8f08212e9360c09791..3c2150273ee85c54276cea8d1af37c9b710afb35 100644 (file)
@@ -218,7 +218,7 @@ func (w *typeWriter) typ(typ Type) {
                                w.string("any")
                                break
                        }
-                       if t == universeComparable.Type().(*Named).underlying {
+                       if t == asNamed(universeComparable.Type()).underlying {
                                w.string("interface{comparable}")
                                break
                        }
@@ -317,6 +317,22 @@ func (w *typeWriter) typ(typ Type) {
                        if w.tpSubscripts || w.ctxt != nil {
                                w.string(subscript(t.id))
                        }
+                       // If the type parameter name is the same as a predeclared object
+                       // (say int), point out where it is declared to avoid confusing
+                       // error messages. This doesn't need to be super-elegant; we just
+                       // need a clear indication that this is not a predeclared name.
+                       if w.ctxt == nil && Universe.Lookup(t.obj.name) != nil {
+                               w.string(fmt.Sprintf(" /* with %s declared at %s */", t.obj.name, t.obj.Pos()))
+                       }
+               }
+
+       case *_Alias:
+               w.typeName(t.obj)
+               if w.ctxt != nil {
+                       // TODO(gri) do we need to print the alias type name, too?
+                       w.typ(_Unalias(t.obj.typ))
+               } else {
+                       w.string(fmt.Sprintf(" /* = %s */", _Unalias(t.obj.typ)))
                }
 
        default: