This is an automated email from the ASF dual-hosted git repository.
dcelasun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git
The following commit(s) were added to refs/heads/master by this push:
new 5eef01f THRIFT-4868: Fix Go compilation for optional sets with
default values (#1802)
5eef01f is described below
commit 5eef01f231b1e7b33d1ebfb65aeb136f851b350b
Author: John Boiles <[email protected]>
AuthorDate: Thu Jun 13 10:49:45 2019 -0700
THRIFT-4868: Fix Go compilation for optional sets with default values
(#1802)
Client: go
---
compiler/cpp/src/thrift/generate/t_go_generator.cc | 8 ++++++--
test/ThriftTest.thrift | 4 ++++
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/compiler/cpp/src/thrift/generate/t_go_generator.cc
b/compiler/cpp/src/thrift/generate/t_go_generator.cc
index 66bb653..c8187d8 100644
--- a/compiler/cpp/src/thrift/generate/t_go_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_go_generator.cc
@@ -3237,8 +3237,12 @@ void
t_go_generator::generate_serialize_container(ostream& out,
t_set* tset = (t_set*)ttype;
out << indent() << "for i := 0; i<len(" << prefix << "); i++ {" << endl;
out << indent() << " for j := i+1; j<len(" << prefix << "); j++ {" <<
endl;
- out << indent() << " if reflect.DeepEqual(" << prefix << "[i]," <<
prefix << "[j]) { " << endl;
- out << indent() << " return thrift.PrependError(\"\", fmt.Errorf(\"%T
error writing set field: slice is not unique\", " << prefix << "[i]))" << endl;
+ string wrapped_prefix = prefix;
+ if (pointer_field) {
+ wrapped_prefix = "(" + prefix + ")";
+ }
+ out << indent() << " if reflect.DeepEqual(" << wrapped_prefix << "[i],"
<< wrapped_prefix << "[j]) { " << endl;
+ out << indent() << " return thrift.PrependError(\"\", fmt.Errorf(\"%T
error writing set field: slice is not unique\", " << wrapped_prefix << "[i]))"
<< endl;
out << indent() << " }" << endl;
out << indent() << " }" << endl;
out << indent() << "}" << endl;
diff --git a/test/ThriftTest.thrift b/test/ThriftTest.thrift
index d1e6b5e..99a15ff 100644
--- a/test/ThriftTest.thrift
+++ b/test/ThriftTest.thrift
@@ -409,3 +409,7 @@ struct StructB {
1: optional StructA aa;
2: required StructA ab;
}
+
+struct OptionalSetDefaultTest {
+ 1: optional set<string> with_default = [ "test" ]
+}