@@ -766,7 +766,13 @@ void t_go_generator::generate_typedef(t_typedef* ttypedef) {
766
766
return ;
767
767
}
768
768
769
- f_types_ << " type " << new_type_name << " " << base_type << endl << endl;
769
+ std::string base_type_name = publicize (ttypedef->get_type ()->get_name ());
770
+ if (ttypedef->get_type ()->is_base_type ()) {
771
+ base_type_name = base_type;
772
+ }
773
+
774
+ f_types_ << " type " << new_type_name << " = " << base_type_name << endl << endl;
775
+
770
776
// Generate a convenience function that converts an instance of a type
771
777
// (which may be a constant) into a pointer to an instance of a type.
772
778
f_types_ << " func " << new_type_name << " Ptr(v " << new_type_name << " ) *" << new_type_name
@@ -1175,8 +1181,9 @@ void t_go_generator::get_publicized_name_and_def_value(t_field* tfield,
1175
1181
1176
1182
void t_go_generator::generate_go_struct_initializer (ostream& out,
1177
1183
t_struct* tstruct,
1178
- bool is_args_or_result) {
1179
- out << publicize (type_name (tstruct), is_args_or_result) << " {" ;
1184
+ bool is_args_or_result,
1185
+ string alias_name) {
1186
+ out << publicize ((alias_name != " " ) ? alias_name : type_name (tstruct), is_args_or_result) << " {" ;
1180
1187
const vector<t_field*>& members = tstruct->get_members ();
1181
1188
for (auto member : members) {
1182
1189
bool pointer_field = is_pointer_field (member);
@@ -3049,7 +3056,8 @@ void t_go_generator::generate_deserialize_field(ostream& out,
3049
3056
(t_struct*)type,
3050
3057
is_pointer_field (tfield, in_container_value),
3051
3058
declare,
3052
- name);
3059
+ name,
3060
+ (orig_type->is_typedef ()) ? orig_type->get_name () : " " );
3053
3061
} else if (type->is_container ()) {
3054
3062
generate_deserialize_container (out, orig_type, is_pointer_field (tfield), declare, name);
3055
3063
} else if (type->is_base_type () || type->is_enum ()) {
@@ -3150,11 +3158,12 @@ void t_go_generator::generate_deserialize_struct(ostream& out,
3150
3158
t_struct* tstruct,
3151
3159
bool pointer_field,
3152
3160
bool declare,
3153
- string prefix) {
3161
+ string prefix,
3162
+ string alias_name) {
3154
3163
string eq (declare ? " := " : " = " );
3155
3164
3156
3165
out << indent () << prefix << eq << (pointer_field ? " &" : " " );
3157
- generate_go_struct_initializer (out, tstruct);
3166
+ generate_go_struct_initializer (out, tstruct, false , alias_name );
3158
3167
out << indent () << " if err := " << prefix << " ." << read_method_name_ << " (ctx, iprot); err != nil {" << endl;
3159
3168
out << indent () << " return thrift.PrependError(fmt.Sprintf(\" %T error reading struct: \" , "
3160
3169
<< prefix << " ), err)" << endl;
@@ -3921,13 +3930,11 @@ string t_go_generator::type_to_go_type(t_type* type) {
3921
3930
* Converts the parse type to a go type, taking into account whether the field
3922
3931
* associated with the type is T_OPTIONAL.
3923
3932
*/
3924
- string t_go_generator::type_to_go_type_with_opt (t_type* type ,
3933
+ string t_go_generator::type_to_go_type_with_opt (t_type* ttype ,
3925
3934
bool optional_field) {
3926
3935
string maybe_pointer (optional_field ? " *" : " " );
3927
3936
3928
- if (type->is_typedef () && ((t_typedef*)type)->is_forward_typedef ()) {
3929
- type = ((t_typedef*)type)->get_true_type ();
3930
- }
3937
+ t_type* type = get_true_type (ttype);
3931
3938
3932
3939
if (type->is_base_type ()) {
3933
3940
t_base_type::t_base tbase = ((t_base_type*)type)->get_base ();
@@ -3970,7 +3977,7 @@ string t_go_generator::type_to_go_type_with_opt(t_type* type,
3970
3977
} else if (type->is_enum ()) {
3971
3978
return maybe_pointer + publicize (type_name (type));
3972
3979
} else if (type->is_struct () || type->is_xception ()) {
3973
- return " *" + publicize (type_name (type ));
3980
+ return " *" + publicize (type_name (ttype ));
3974
3981
} else if (type->is_map ()) {
3975
3982
t_map* t = (t_map*)type;
3976
3983
string keyType = type_to_go_key_type (t->get_key_type ());
@@ -3984,8 +3991,6 @@ string t_go_generator::type_to_go_type_with_opt(t_type* type,
3984
3991
t_list* t = (t_list*)type;
3985
3992
string elemType = type_to_go_type (t->get_elem_type ());
3986
3993
return maybe_pointer + string (" []" ) + elemType;
3987
- } else if (type->is_typedef ()) {
3988
- return maybe_pointer + publicize (type_name (type));
3989
3994
}
3990
3995
3991
3996
throw " INVALID TYPE IN type_to_go_type: " + type->get_name ();
0 commit comments