diff mbox series

Go patch committed: Parenthesize channel type strings as needed

Message ID CAOyqgcXCGSLRSL8iSRkatAr8G7LC6Tybxj07hwLS4rwwVxtUYw@mail.gmail.com
State New
Headers show
Series Go patch committed: Parenthesize channel type strings as needed | expand

Commit Message

Ian Lance Taylor Dec. 24, 2020, 1:50 a.m. UTC
This patch to the Go frontend avoids the ambiguity between "chan <-
(chan int)" and "chan (<- chan int)".  This parenthesizes the same way
as the gc compiler.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
a40029e3b185a4b4e16a2a83933f742ff48c9743
diff mbox series

Patch

diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 600d9769624..1e461f06e95 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -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.
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc
index 16f0eb59a50..7d4c47f1c42 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -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.