diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-12-23 16:32:30 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-12-23 17:50:31 -0800 |
commit | 085fd2a46e512638a4d7a96e07eaf3b8b021a567 (patch) | |
tree | 58395ab15b5f609c411312db2bd6701d1fa08cf3 /gcc/go/gofrontend | |
parent | 85d8ebcfc235e71bf52e7bf1d3864e1b95689091 (diff) | |
download | gcc-085fd2a46e512638a4d7a96e07eaf3b8b021a567.zip gcc-085fd2a46e512638a4d7a96e07eaf3b8b021a567.tar.gz gcc-085fd2a46e512638a4d7a96e07eaf3b8b021a567.tar.bz2 |
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
Diffstat (limited to 'gcc/go/gofrontend')
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/types.cc | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 600d976..1e461f0 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 16f0eb5..7d4c47f 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. |