THRIFT-4868: Fix Go compilation for optional sets with default values (#1802)

Client: go
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 @@
     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 @@
   1: optional StructA aa;
   2: required StructA ab;
 }
+
+struct OptionalSetDefaultTest {
+  1: optional set<string> with_default = [ "test" ]
+}