public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Ian Lance Taylor <ian@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-6331] compiler: parenthesize channel type strings if necessary
Date: Thu, 24 Dec 2020 01:50:44 +0000 (GMT)	[thread overview]
Message-ID: <20201224015044.E3DDC3851C23@sourceware.org> (raw)

https://gcc.gnu.org/g:085fd2a46e512638a4d7a96e07eaf3b8b021a567

commit r11-6331-g085fd2a46e512638a4d7a96e07eaf3b8b021a567
Author: Ian Lance Taylor <iant@golang.org>
Date:   Wed Dec 23 16:32:30 2020 -0800

    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.
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/279961

Diff:
---
 gcc/go/gofrontend/MERGE    |  2 +-
 gcc/go/gofrontend/types.cc | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

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.


                 reply	other threads:[~2020-12-24  1:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201224015044.E3DDC3851C23@sourceware.org \
    --to=ian@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).