mirror of
https://github.com/golang/go
synced 2024-09-05 16:04:50 +00:00
cmd/compile: support reading union type for compiler backend in unified IR
Fixes #52124 Change-Id: I5749822d41d8e51f476bceb277b1d2cf7350dcc3 Reviewed-on: https://go-review.googlesource.com/c/go/+/397874 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
c8110c3df6
commit
efbe17d6f1
|
@ -442,9 +442,21 @@ func (r *reader) doTyp() *types.Type {
|
||||||
return r.structType()
|
return r.structType()
|
||||||
case pkgbits.TypeInterface:
|
case pkgbits.TypeInterface:
|
||||||
return r.interfaceType()
|
return r.interfaceType()
|
||||||
|
case pkgbits.TypeUnion:
|
||||||
|
return r.unionType()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *reader) unionType() *types.Type {
|
||||||
|
terms := make([]*types.Type, r.Len())
|
||||||
|
tildes := make([]bool, len(terms))
|
||||||
|
for i := range terms {
|
||||||
|
tildes[i] = r.Bool()
|
||||||
|
terms[i] = r.typ()
|
||||||
|
}
|
||||||
|
return types.NewUnion(terms, tildes)
|
||||||
|
}
|
||||||
|
|
||||||
func (r *reader) interfaceType() *types.Type {
|
func (r *reader) interfaceType() *types.Type {
|
||||||
tpkg := types.LocalPkg // TODO(mdempsky): Remove after iexport is gone.
|
tpkg := types.LocalPkg // TODO(mdempsky): Remove after iexport is gone.
|
||||||
|
|
||||||
|
|
9
test/typeparam/issue52124.go
Normal file
9
test/typeparam/issue52124.go
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// compile
|
||||||
|
|
||||||
|
// Copyright 2022 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package p
|
||||||
|
|
||||||
|
type I interface{ any | int }
|
Loading…
Reference in a new issue