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 {
|
if n.Dir == SendOnly {
|
||||||
p.print(_Arrow)
|
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
|
// statements
|
||||||
case *DeclStmt:
|
case *DeclStmt:
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,28 @@ func TestPrint(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var stringTests = []string{
|
||||||
|
"package p",
|
||||||
|
"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) {
|
func TestPrintString(t *testing.T) {
|
||||||
for _, want := range []string{
|
for _, want := range stringTests {
|
||||||
"package p",
|
|
||||||
"package p; type _ = int; type T1 = struct{}; type ( _ = *struct{}; T2 = float32 )",
|
|
||||||
// TODO(gri) expand
|
|
||||||
} {
|
|
||||||
ast, err := Parse(nil, strings.NewReader(want), nil, nil, 0)
|
ast, err := Parse(nil, strings.NewReader(want), nil, nil, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue