diff options
author | Robert Griesemer <gri@golang.org> | 2021-05-25 17:49:32 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-06-02 20:31:01 +0000 |
commit | 589e32dbdf89484d620c635a966c736085cae5c4 (patch) | |
tree | 75e1633438a390fa4dab5a4f010e813441636d5c /src/cmd/compile/internal/types2/index.go | |
parent | 7b876def6c4936cfae774d3007f8265876a9fbf7 (diff) | |
download | go-589e32dbdf89484d620c635a966c736085cae5c4.tar.gz go-589e32dbdf89484d620c635a966c736085cae5c4.zip |
[dev.typeparams] cmd/compile/internal/types2: replace Sum type with Union type
- We still mostly ignore the tilde information.
- More consistent naming: A Union term is the pair (type, tilde).
Rename Union.terms to Union.types; the Union.types and Union.tilde
slices make up the Union terms.
- Replace Sum.is with Union.underIs: underIs iterates through all
union terms and calls its argument function with the underlying
type of the term (and thus can ignore the tilde information).
This also eliminates the need to call under in the argument
function.
- Added Union.is for situations where we need to consider the tilde
information for each Union term.
Change-Id: I70fcf1813e072651dc0f61d52d5555642ee762fd
Reviewed-on: https://go-review.googlesource.com/c/go/+/323274
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/index.go')
-rw-r--r-- | src/cmd/compile/internal/types2/index.go | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/cmd/compile/internal/types2/index.go b/src/cmd/compile/internal/types2/index.go index 33e79aac3e..47e0853a3b 100644 --- a/src/cmd/compile/internal/types2/index.go +++ b/src/cmd/compile/internal/types2/index.go @@ -91,15 +91,15 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo x.expr = e return - case *Sum: - // A sum type can be indexed if all of the sum's types + case *Union: + // A union type can be indexed if all of the union's terms // support indexing and have the same index and element - // type. Special rules apply for maps in the sum type. + // type. Special rules apply for maps in the union type. var tkey, telem Type // key is for map types only - nmaps := 0 // number of map types in sum type - if typ.is(func(t Type) bool { + nmaps := 0 // number of map types in union type + if typ.underIs(func(t Type) bool { var e Type - switch t := under(t).(type) { + switch t := t.(type) { case *Basic: if isString(t) { e = universeByte @@ -113,7 +113,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo case *Slice: e = t.elem case *Map: - // If there are multiple maps in the sum type, + // If there are multiple maps in the union type, // they must have identical key types. // TODO(gri) We may be able to relax this rule // but it becomes complicated very quickly. @@ -148,7 +148,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo // ok to continue even if indexing failed - map element type is known // If there are only maps, we are done. - if nmaps == len(typ.types) { + if nmaps == typ.NumTerms() { x.mode = mapindex x.typ = telem x.expr = e @@ -246,7 +246,7 @@ func (check *Checker) sliceExpr(x *operand, e *syntax.SliceExpr) { valid = true // x.typ doesn't change - case *Sum, *TypeParam: + case *Union, *TypeParam: check.error(x, "generic slice expressions not yet implemented") x.mode = invalid return |