aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types/size.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-05-24 20:36:42 -0700
committerDan Scales <danscales@google.com>2021-05-26 15:33:02 +0000
commitfd54ae8b0c7ed3ef9869112586069f7cac82cf1e (patch)
treef328bab9546644f1ed7c6a947871850952e6f6d8 /src/cmd/compile/internal/types/size.go
parent6c9e1c58bc7661638ee084e40a3b6fc907825496 (diff)
downloadgo-fd54ae8b0c7ed3ef9869112586069f7cac82cf1e.tar.gz
go-fd54ae8b0c7ed3ef9869112586069f7cac82cf1e.zip
[dev.typeparams] cmd/compile: adding union support in types1
Add union support in types1, and allow exporting of unions, and importing unions back into types1 and types2. Added new test mincheck.go/mincheck.dir that tests that type lists (type sets) are correctly exported/imported, so that types2 gives correct errors that an instantiation doesn't fit the type list in the type param constraint. Change-Id: I8041c6c79289c870a95ed5a1b10e4c1c16985b12 Reviewed-on: https://go-review.googlesource.com/c/go/+/322609 Trust: Dan Scales <danscales@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/types/size.go')
-rw-r--r--src/cmd/compile/internal/types/size.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/types/size.go b/src/cmd/compile/internal/types/size.go
index f0e695ab96..7059eff398 100644
--- a/src/cmd/compile/internal/types/size.go
+++ b/src/cmd/compile/internal/types/size.go
@@ -104,8 +104,14 @@ func expandiface(t *Type) {
continue
}
+ if m.Type.IsUnion() {
+ continue
+ }
+
+ // Once we go to 1.18, then embedded types can be anything, but
+ // for now, just interfaces and unions.
if !m.Type.IsInterface() {
- base.ErrorfAt(m.Pos, "interface contains embedded non-interface %v", m.Type)
+ base.ErrorfAt(m.Pos, "interface contains embedded non-interface, non-union %v", m.Type)
m.SetBroke(true)
t.SetBroke(true)
// Add to fields so that error messages
@@ -405,6 +411,12 @@ func CalcSize(t *Type) {
t.Align = uint8(PtrSize)
expandiface(t)
+ case TUNION:
+ // Always part of an interface for now, so size/align don't matter.
+ // Pretend a union is represented like an interface.
+ w = 2 * int64(PtrSize)
+ t.Align = uint8(PtrSize)
+
case TCHAN: // implemented as pointer
w = int64(PtrSize)