mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.typeparams] cmd/compile/internal/syntax: fix printing of channel types
Change-Id: I80a3ca77d0642711913c9584e70059e4ed668860 Reviewed-on: https://go-review.googlesource.com/c/go/+/262444 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
73f529845c
commit
e9e58a4d49
2 changed files with 30 additions and 6 deletions
|
|
@ -484,7 +484,15 @@ func (p *printer) printRawNode(n Node) {
|
|||
if n.Dir == SendOnly {
|
||||
p.print(_Arrow)
|
||||
}
|
||||
p.print(blank, n.Elem)
|
||||
p.print(blank)
|
||||
if e, _ := n.Elem.(*ChanType); n.Dir == 0 && e != nil && e.Dir == RecvOnly {
|
||||
// don't print chan (<-chan T) as chan <-chan T
|
||||
p.print(_Lparen)
|
||||
p.print(n.Elem)
|
||||
p.print(_Rparen)
|
||||
} else {
|
||||
p.print(n.Elem)
|
||||
}
|
||||
|
||||
// statements
|
||||
case *DeclStmt:
|
||||
|
|
|
|||
|
|
@ -30,12 +30,28 @@ func TestPrint(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPrintString(t *testing.T) {
|
||||
for _, want := range []string{
|
||||
var stringTests = []string{
|
||||
"package p",
|
||||
"package p; type _ = int; type T1 = struct{}; type ( _ = *struct{}; T2 = float32 )",
|
||||
"package p; type _ int; type T1 = struct{}; type ( _ *struct{}; T2 = float32 )",
|
||||
|
||||
// channels
|
||||
"package p; type _ chan chan int",
|
||||
"package p; type _ chan (<-chan int)",
|
||||
"package p; type _ chan chan<- int",
|
||||
|
||||
"package p; type _ <-chan chan int",
|
||||
"package p; type _ <-chan <-chan int",
|
||||
"package p; type _ <-chan chan<- int",
|
||||
|
||||
"package p; type _ chan<- chan int",
|
||||
"package p; type _ chan<- <-chan int",
|
||||
"package p; type _ chan<- chan<- int",
|
||||
|
||||
// TODO(gri) expand
|
||||
} {
|
||||
}
|
||||
|
||||
func TestPrintString(t *testing.T) {
|
||||
for _, want := range stringTests {
|
||||
ast, err := Parse(nil, strings.NewReader(want), nil, nil, 0)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue