compiler: parenthesize channel type strings if necessary
Avoid the ambiguity between "chan <- (chan int)" and "chan (<- chan int)".
This parenthesizes the same way as the gc compiler.
Change-Id: I638c89058c48c486121ecb67a5f7285f099505c7
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/279961
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/go/types.cc b/go/types.cc
index 16f0eb5..7d4c47f 100644
--- a/go/types.cc
+++ b/go/types.cc
@@ -8845,7 +8845,22 @@
if (!this->may_receive_)
ret->append("<-");
ret->push_back(' ');
+
+ bool need_paren = false;
+ if (this->may_send_
+ && this->may_receive_
+ && this->element_type_->channel_type() != NULL
+ && this->element_type_->unalias()->named_type() == NULL
+ && !this->element_type_->channel_type()->may_send())
+ {
+ ret->push_back('(');
+ need_paren = true;
+ }
+
this->append_reflection(this->element_type_, gogo, ret);
+
+ if (need_paren)
+ ret->push_back(')');
}
// Export.