diff --git a/third-party/thrift/src/thrift/compiler/generate/templates/go/types/struct_method_new.mustache b/third-party/thrift/src/thrift/compiler/generate/templates/go/types/struct_method_new.mustache index 1d608a526e4b3d..775e0c7ceadc00 100644 --- a/third-party/thrift/src/thrift/compiler/generate/templates/go/types/struct_method_new.mustache +++ b/third-party/thrift/src/thrift/compiler/generate/templates/go/types/struct_method_new.mustache @@ -21,6 +21,7 @@ }} func {{struct:go_qualified_new_func}}() *{{struct:go_name}} { return (&{{struct:go_name}}{}){{! + }}{{^struct:union?}}{{! }}{{#struct:fields}}{{! // Fields with given default values. @@ -46,6 +47,7 @@ func {{struct:go_qualified_new_func}}() *{{struct:go_name}} { }}){{/field:optional?}}{{! }}{{/field:value}}{{! - }}{{/struct:fields}} + }}{{/struct:fields}}{{! + }}{{/struct:union?}} } {{!newline}} diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/adapter/gen-go_mstch/module/types.go b/third-party/thrift/src/thrift/compiler/test/fixtures/adapter/gen-go_mstch/module/types.go index 880241ee2e33f0..adfa6763468d6f 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/adapter/gen-go_mstch/module/types.go +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/adapter/gen-go_mstch/module/types.go @@ -2032,12 +2032,7 @@ type Baz struct { var _ thrift.Struct = &Baz{} func NewBaz() *Baz { - return (&Baz{}). - SetIntFieldNonCompat(0). - SetSetFieldNonCompat(NewSetWithAdapter()). - SetMapFieldNonCompat(make(map[string]ListWithElemAdapterWithAdapter)). - SetBinaryFieldNonCompat([]byte("")). - SetLongFieldNonCompat(NewMyI64()) + return (&Baz{}) } func (x *Baz) GetIntFieldNonCompat() *int32 { @@ -7303,9 +7298,7 @@ type AdaptTestUnion struct { var _ thrift.Struct = &AdaptTestUnion{} func NewAdaptTestUnion() *AdaptTestUnion { - return (&AdaptTestUnion{}). - SetDelayNonCompat(NewDurationMs()). - SetCustomNonCompat(NewCustomProtocolType()) + return (&AdaptTestUnion{}) } func (x *AdaptTestUnion) GetDelayNonCompat() *DurationMs { diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/basic/gen-go_mstch/module/types.go b/third-party/thrift/src/thrift/compiler/test/fixtures/basic/gen-go_mstch/module/types.go index 04b2d588a3abed..7ca972b4b05296 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/basic/gen-go_mstch/module/types.go +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/basic/gen-go_mstch/module/types.go @@ -894,11 +894,7 @@ type MyUnion struct { var _ thrift.Struct = &MyUnion{} func NewMyUnion() *MyUnion { - return (&MyUnion{}). - SetMyEnumNonCompat(0). - SetMyStructNonCompat(*NewMyStruct()). - SetMyDataItemNonCompat(*NewMyDataItem()). - SetFloatSetNonCompat(make([]float32, 0)) + return (&MyUnion{}) } func (x *MyUnion) GetMyEnumNonCompat() *MyEnum { @@ -1475,8 +1471,7 @@ type UnionToBeRenamed struct { var _ thrift.Struct = &UnionToBeRenamed{} func NewUnionToBeRenamed() *UnionToBeRenamed { - return (&UnionToBeRenamed{}). - SetReservedFieldNonCompat(0) + return (&UnionToBeRenamed{}) } func (x *UnionToBeRenamed) GetReservedFieldNonCompat() *int32 { diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/complex-union/gen-go_mstch/module/types.go b/third-party/thrift/src/thrift/compiler/test/fixtures/complex-union/gen-go_mstch/module/types.go index 81371c1d0ff0c7..9d17f8d0e08d86 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/complex-union/gen-go_mstch/module/types.go +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/complex-union/gen-go_mstch/module/types.go @@ -99,13 +99,7 @@ type ComplexUnion struct { var _ thrift.Struct = &ComplexUnion{} func NewComplexUnion() *ComplexUnion { - return (&ComplexUnion{}). - SetIntValueNonCompat(0). - SetStringValueNonCompat(""). - SetIntListValueNonCompat(make([]int64, 0)). - SetStringListValueNonCompat(make([]string, 0)). - SetTypedefValueNonCompat(NewContainerTypedef()). - SetStringRefNonCompat("") + return (&ComplexUnion{}) } func (x *ComplexUnion) GetIntValueNonCompat() *int64 { @@ -699,9 +693,7 @@ type ListUnion struct { var _ thrift.Struct = &ListUnion{} func NewListUnion() *ListUnion { - return (&ListUnion{}). - SetIntListValueNonCompat(make([]int64, 0)). - SetStringListValueNonCompat(make([]string, 0)) + return (&ListUnion{}) } func (x *ListUnion) GetIntListValueNonCompat() []int64 { @@ -997,9 +989,7 @@ type DataUnion struct { var _ thrift.Struct = &DataUnion{} func NewDataUnion() *DataUnion { - return (&DataUnion{}). - SetBinaryDataNonCompat([]byte("")). - SetStringDataNonCompat("") + return (&DataUnion{}) } func (x *DataUnion) GetBinaryDataNonCompat() []byte { @@ -1510,9 +1500,7 @@ type ValUnion struct { var _ thrift.Struct = &ValUnion{} func NewValUnion() *ValUnion { - return (&ValUnion{}). - SetV1NonCompat(*NewVal()). - SetV2NonCompat(*NewVal()) + return (&ValUnion{}) } func (x *ValUnion) GetV1NonCompat() *Val { @@ -1774,9 +1762,7 @@ type VirtualComplexUnion struct { var _ thrift.Struct = &VirtualComplexUnion{} func NewVirtualComplexUnion() *VirtualComplexUnion { - return (&VirtualComplexUnion{}). - SetThingOneNonCompat(""). - SetThingTwoNonCompat("") + return (&VirtualComplexUnion{}) } func (x *VirtualComplexUnion) GetThingOneNonCompat() *string { @@ -2158,8 +2144,7 @@ type NonCopyableUnion struct { var _ thrift.Struct = &NonCopyableUnion{} func NewNonCopyableUnion() *NonCopyableUnion { - return (&NonCopyableUnion{}). - SetSNonCompat(*NewNonCopyableStruct()) + return (&NonCopyableUnion{}) } func (x *NonCopyableUnion) GetSNonCompat() *NonCopyableStruct { diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/constants/gen-go_mstch/module/types.go b/third-party/thrift/src/thrift/compiler/test/fixtures/constants/gen-go_mstch/module/types.go index e0f971d883ec2f..c74d9ea34dcc97 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/constants/gen-go_mstch/module/types.go +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/constants/gen-go_mstch/module/types.go @@ -2111,9 +2111,7 @@ type Union1 struct { var _ thrift.Struct = &Union1{} func NewUnion1() *Union1 { - return (&Union1{}). - SetINonCompat(0). - SetDNonCompat(0.0) + return (&Union1{}) } func (x *Union1) GetINonCompat() *int32 { @@ -2359,11 +2357,7 @@ type Union2 struct { var _ thrift.Struct = &Union2{} func NewUnion2() *Union2 { - return (&Union2{}). - SetINonCompat(0). - SetDNonCompat(0.0). - SetSNonCompat(*NewStruct1()). - SetUNonCompat(*NewUnion1()) + return (&Union2{}) } func (x *Union2) GetINonCompat() *int32 { diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/doctext/gen-go_mstch/module/types.go b/third-party/thrift/src/thrift/compiler/test/fixtures/doctext/gen-go_mstch/module/types.go index 47828bd4c7e6a1..23eb87fd639f64 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/doctext/gen-go_mstch/module/types.go +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/doctext/gen-go_mstch/module/types.go @@ -264,9 +264,7 @@ type U struct { var _ thrift.Struct = &U{} func NewU() *U { - return (&U{}). - SetINonCompat(0). - SetSNonCompat("") + return (&U{}) } func (x *U) GetINonCompat() *int32 { diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/no-legacy-apis/gen-go_mstch/module/types.go b/third-party/thrift/src/thrift/compiler/test/fixtures/no-legacy-apis/gen-go_mstch/module/types.go index e0fc5294593b86..bd202a6ec07ba1 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/no-legacy-apis/gen-go_mstch/module/types.go +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/no-legacy-apis/gen-go_mstch/module/types.go @@ -278,9 +278,7 @@ type MyUnion struct { var _ thrift.Struct = &MyUnion{} func NewMyUnion() *MyUnion { - return (&MyUnion{}). - SetMyEnumNonCompat(0). - SetMyDataItemNonCompat(*NewMyStruct()) + return (&MyUnion{}) } func (x *MyUnion) GetMyEnumNonCompat() *MyEnum { diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/patch/gen-go_mstch/module/types.go b/third-party/thrift/src/thrift/compiler/test/fixtures/patch/gen-go_mstch/module/types.go index 90e1eb2438f07e..a10765a69eb390 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/patch/gen-go_mstch/module/types.go +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/patch/gen-go_mstch/module/types.go @@ -474,8 +474,7 @@ type InnerUnion struct { var _ thrift.Struct = &InnerUnion{} func NewInnerUnion() *InnerUnion { - return (&InnerUnion{}). - SetInnerOptionNonCompat([]byte("")) + return (&InnerUnion{}) } func (x *InnerUnion) GetInnerOptionNonCompat() []byte { @@ -642,10 +641,7 @@ type MyUnion struct { var _ thrift.Struct = &MyUnion{} func NewMyUnion() *MyUnion { - return (&MyUnion{}). - SetOption1NonCompat(""). - SetOption2NonCompat(0). - SetOption3NonCompat(*NewInnerUnion()) + return (&MyUnion{}) } func (x *MyUnion) GetOption1NonCompat() *string { diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/patch/gen-go_mstch/thrift/lib/thrift/standard/types.go b/third-party/thrift/src/thrift/compiler/test/fixtures/patch/gen-go_mstch/thrift/lib/thrift/standard/types.go index e5c680e1425272..f9e52d0878f8f7 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/patch/gen-go_mstch/thrift/lib/thrift/standard/types.go +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/patch/gen-go_mstch/thrift/lib/thrift/standard/types.go @@ -225,9 +225,7 @@ type TypeUri struct { var _ thrift.Struct = &TypeUri{} func NewTypeUri() *TypeUri { - return (&TypeUri{}). - SetUriNonCompat(NewUri()). - SetTypeHashPrefixSha2_256NonCompat(NewByteString()) + return (&TypeUri{}) } func (x *TypeUri) GetUriNonCompat() *Uri { @@ -485,24 +483,7 @@ type TypeName struct { var _ thrift.Struct = &TypeName{} func NewTypeName() *TypeName { - return (&TypeName{}). - SetBoolTypeNonCompat(0). - SetByteTypeNonCompat(0). - SetI16TypeNonCompat(0). - SetI32TypeNonCompat(0). - SetI64TypeNonCompat(0). - SetFloatTypeNonCompat(0). - SetDoubleTypeNonCompat(0). - SetStringTypeNonCompat(0). - SetBinaryTypeNonCompat(0). - SetEnumTypeNonCompat(*NewTypeUri()). - SetTypedefTypeNonCompat(*NewTypeUri()). - SetStructTypeNonCompat(*NewTypeUri()). - SetUnionTypeNonCompat(*NewTypeUri()). - SetExceptionTypeNonCompat(*NewTypeUri()). - SetListTypeNonCompat(0). - SetSetTypeNonCompat(0). - SetMapTypeNonCompat(0) + return (&TypeName{}) } func (x *TypeName) GetBoolTypeNonCompat() *Void { diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/terse_write/gen-go_mstch/terse_write/types.go b/third-party/thrift/src/thrift/compiler/test/fixtures/terse_write/gen-go_mstch/terse_write/types.go index ebd546fb310e4d..adb76a295e4538 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/terse_write/gen-go_mstch/terse_write/types.go +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/terse_write/gen-go_mstch/terse_write/types.go @@ -202,21 +202,7 @@ type MyUnion struct { var _ thrift.Struct = &MyUnion{} func NewMyUnion() *MyUnion { - return (&MyUnion{}). - SetBoolFieldNonCompat(false). - SetByteFieldNonCompat(0). - SetShortFieldNonCompat(0). - SetIntFieldNonCompat(0). - SetLongFieldNonCompat(0). - SetFloatFieldNonCompat(0.0). - SetDoubleFieldNonCompat(0.0). - SetStringFieldNonCompat(""). - SetBinaryFieldNonCompat([]byte("")). - SetEnumFieldNonCompat(0). - SetListFieldNonCompat(make([]int16, 0)). - SetSetFieldNonCompat(make([]int16, 0)). - SetMapFieldNonCompat(make(map[int16]int16)). - SetStructFieldNonCompat(*NewMyStruct()) + return (&MyUnion{}) } func (x *MyUnion) GetBoolFieldNonCompat() *bool {