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