THRIFT-2112 Error in Go generator when using typedefs in map keys
Patch: Emir Habul
diff --git a/compiler/cpp/src/generate/t_go_generator.cc b/compiler/cpp/src/generate/t_go_generator.cc
index 43c4766..288bfab 100644
--- a/compiler/cpp/src/generate/t_go_generator.cc
+++ b/compiler/cpp/src/generate/t_go_generator.cc
@@ -3175,15 +3175,14 @@
*/
string t_go_generator::type_to_go_key_type(t_type* type)
{
- string go_type = type_to_go_type(type);
+ t_type* resolved_type = type;
- while (type->is_typedef()) {
- type = ((t_typedef*)type)->get_type();
+ while (resolved_type->is_typedef()) {
+ resolved_type = ((t_typedef*)resolved_type)->get_type();
}
- if (type->is_map() || type->is_list() || type->is_set()) {
+ if (resolved_type->is_map() || resolved_type->is_list() || resolved_type->is_set()) {
throw "Cannot produce a valid type for a Go map key: " + type_to_go_type(type) + " - aborting.";
-
}
return type_to_go_type(type);
diff --git a/lib/go/test/IncludesTest.thrift b/lib/go/test/IncludesTest.thrift
index 6f80e6b..3f60321 100644
--- a/lib/go/test/IncludesTest.thrift
+++ b/lib/go/test/IncludesTest.thrift
@@ -55,3 +55,13 @@
void extendedMethod3(),
}
+typedef map<ThriftTest.UserId, map<NamespacedTest.UserId, list<TestStruct2> > > ComplexMapType
+
+struct ComplexMapStruct {
+ 1: ComplexMapType complex,
+}
+
+service ComplexMapService {
+ ComplexMapStruct transformMap(1: ComplexMapStruct input),
+}
+