compiler: parenthesize channel type strings if necessary
authorIan Lance Taylor <iant@golang.org>
Thu, 24 Dec 2020 00:32:30 +0000 (16:32 -0800)
committerIan Lance Taylor <iant@golang.org>
Thu, 24 Dec 2020 01:50:31 +0000 (17:50 -0800)
Avoid the ambiguity between "chan <- (chan int)" and "chan (<- chan int)".
This parenthesizes the same way as the gc compiler.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/279961

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/types.cc

index 600d976962493fa5448b1a2c617a22cf0c2f0dcb..1e461f06e951cc13841ec6b2293c1801e8c72029 100644 (file)
@@ -1,4 +1,4 @@
-8d49adead59b8103f3bfeebd53ee508eda5ee94a
+d67579759e1769c08148304b2d378ec0b05637d6
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index 16f0eb59a503a540bfe6cf1e8bfa4e62398e5f57..7d4c47f1c42621ea33606b7b509f55fd07788c2e 100644 (file)
@@ -8845,7 +8845,22 @@ Channel_type::do_reflection(Gogo* gogo, std::string* ret) const
   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.