Skip to content

Commit efbe17d

Browse files
committed
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>
1 parent c8110c3 commit efbe17d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/cmd/compile/internal/noder/reader.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,21 @@ func (r *reader) doTyp() *types.Type {
442442
return r.structType()
443443
case pkgbits.TypeInterface:
444444
return r.interfaceType()
445+
case pkgbits.TypeUnion:
446+
return r.unionType()
445447
}
446448
}
447449

450+
func (r *reader) unionType() *types.Type {
451+
terms := make([]*types.Type, r.Len())
452+
tildes := make([]bool, len(terms))
453+
for i := range terms {
454+
tildes[i] = r.Bool()
455+
terms[i] = r.typ()
456+
}
457+
return types.NewUnion(terms, tildes)
458+
}
459+
448460
func (r *reader) interfaceType() *types.Type {
449461
tpkg := types.LocalPkg // TODO(mdempsky): Remove after iexport is gone.
450462

test/typeparam/issue52124.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// compile
2+
3+
// Copyright 2022 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package p
8+
9+
type I interface{ any | int }

0 commit comments

Comments
 (0)