aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/typestring.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-05-20 15:13:04 -0700
committerRobert Griesemer <gri@golang.org>2021-05-24 23:16:07 +0000
commit5770d7a63743ddfd0e78877f162cbbf18ffb9c1d (patch)
treeee9d3626479a6ac8589dc7b446c24365281456bc /src/cmd/compile/internal/types2/typestring.go
parentcc7ceea5859beb5569d1a278e389ae7dd7d13f8b (diff)
downloadgo-5770d7a63743ddfd0e78877f162cbbf18ffb9c1d.tar.gz
go-5770d7a63743ddfd0e78877f162cbbf18ffb9c1d.zip
[dev.typeparams] cmd/compile/internal/types2: accept embedded interface elements
Accept embedded interface elements of the form ~T or A|B and treat them like type lists: for now the elements of a union cannot be interfaces. Also, translate existing style "type"- lists in interfaces into interface elements: "type a, b, c" becomes a union element "~a|~b|~c" which in turn is handled internally like a type list. For now, "~" is still ignored and type lists are mapped to Sum types as before, thus ensuring that all existing tests work as before (with some minor adjustments). Introduced a new Union type to represent union elements. For now they don't make it past interface completion where they are represented as a Sum type. Thus, except for printing (and the respective tests) and substitution for interfaces, the various type switches ignore Union types. In a next step, we'll replace Sum types with union types and then consider the ~ functionality as well. Because union elements are no different from embedded interfaces we don't need a separate Interface.types field anymore. Removed. For #45346. Change-Id: I98ac3286aea9d706e98aee80241d4712ed99af08 Reviewed-on: https://go-review.googlesource.com/c/go/+/321689 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/typestring.go')
-rw-r--r--src/cmd/compile/internal/types2/typestring.go21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/cmd/compile/internal/types2/typestring.go b/src/cmd/compile/internal/types2/typestring.go
index c534b04130..55858b7b42 100644
--- a/src/cmd/compile/internal/types2/typestring.go
+++ b/src/cmd/compile/internal/types2/typestring.go
@@ -158,11 +158,17 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) {
writeSignature(buf, t, qf, visited)
case *Sum:
- for i, t := range t.types {
+ writeTypeList(buf, t.types, qf, visited)
+
+ case *Union:
+ for i, e := range t.terms {
if i > 0 {
- buf.WriteString(", ")
+ buf.WriteString("|")
}
- writeType(buf, t, qf, visited)
+ if t.tilde[i] {
+ buf.WriteByte('~')
+ }
+ writeType(buf, e, qf, visited)
}
case *Interface:
@@ -207,14 +213,6 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) {
writeSignature(buf, m.typ.(*Signature), qf, visited)
empty = false
}
- if !empty && t.types != nil {
- buf.WriteString("; ")
- }
- if t.types != nil {
- buf.WriteString("type ")
- writeType(buf, t.types, qf, visited)
- empty = false
- }
if !empty && len(t.embeddeds) > 0 {
buf.WriteString("; ")
}
@@ -307,6 +305,7 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) {
default:
// For externally defined implementations of Type.
+ // Note: In this case cycles won't be caught.
buf.WriteString(t.String())
}
}