diff --git a/Makefile b/Makefile index 68a02b1669..19528c8f94 100755 --- a/Makefile +++ b/Makefile @@ -137,6 +137,7 @@ regenerate: make -C test/issue503 regenerate make -C test/issue530 regenerate make -C test/issue617 regenerate + make -C test/issue630 regenerate make gofmt diff --git a/plugin/gostring/gostring.go b/plugin/gostring/gostring.go index 6003d65f22..bc89a7b871 100644 --- a/plugin/gostring/gostring.go +++ b/plugin/gostring/gostring.go @@ -238,10 +238,10 @@ func (p *gostring) Generate(file *generator.FileDescriptor) { } else { goTyp, _ := p.GoType(message, field) goTyp = strings.Replace(goTyp, "[]", "", 1) - p.P("vs := make([]*", goTyp, ", len(this.", fieldname, "))") + p.P("vs := make([]", goTyp, ", len(this.", fieldname, "))") p.P("for i := range vs {") p.In() - p.P("vs[i] = &this.", fieldname, "[i]") + p.P("vs[i] = this.", fieldname, "[i]") p.Out() p.P("}") p.P(`s = append(s, "`, fieldname, `: " + `, fmtPkg.Use(), `.Sprintf("%#v", vs) + ",\n")`) diff --git a/test/combos/both/thetest.pb.go b/test/combos/both/thetest.pb.go index 0c02cab405..b1f0e7e1da 100644 --- a/test/combos/both/thetest.pb.go +++ b/test/combos/both/thetest.pb.go @@ -20799,16 +20799,16 @@ func (this *NidRepStruct) GoString() string { s = append(s, "Field2: "+fmt.Sprintf("%#v", this.Field2)+",\n") } if this.Field3 != nil { - vs := make([]*NidOptNative, len(this.Field3)) + vs := make([]NidOptNative, len(this.Field3)) for i := range vs { - vs[i] = &this.Field3[i] + vs[i] = this.Field3[i] } s = append(s, "Field3: "+fmt.Sprintf("%#v", vs)+",\n") } if this.Field4 != nil { - vs := make([]*NinOptNative, len(this.Field4)) + vs := make([]NinOptNative, len(this.Field4)) for i := range vs { - vs[i] = &this.Field4[i] + vs[i] = this.Field4[i] } s = append(s, "Field4: "+fmt.Sprintf("%#v", vs)+",\n") } @@ -20819,9 +20819,9 @@ func (this *NidRepStruct) GoString() string { s = append(s, "Field7: "+fmt.Sprintf("%#v", this.Field7)+",\n") } if this.Field8 != nil { - vs := make([]*NidOptNative, len(this.Field8)) + vs := make([]NidOptNative, len(this.Field8)) for i := range vs { - vs[i] = &this.Field8[i] + vs[i] = this.Field8[i] } s = append(s, "Field8: "+fmt.Sprintf("%#v", vs)+",\n") } @@ -20928,9 +20928,9 @@ func (this *NidNestedStruct) GoString() string { s = append(s, "&test.NidNestedStruct{") s = append(s, "Field1: "+strings.Replace(this.Field1.GoString(), `&`, ``, 1)+",\n") if this.Field2 != nil { - vs := make([]*NidRepStruct, len(this.Field2)) + vs := make([]NidRepStruct, len(this.Field2)) for i := range vs { - vs[i] = &this.Field2[i] + vs[i] = this.Field2[i] } s = append(s, "Field2: "+fmt.Sprintf("%#v", vs)+",\n") } diff --git a/test/combos/marshaler/thetest.pb.go b/test/combos/marshaler/thetest.pb.go index ee2a83afa5..a5340326c7 100644 --- a/test/combos/marshaler/thetest.pb.go +++ b/test/combos/marshaler/thetest.pb.go @@ -20798,16 +20798,16 @@ func (this *NidRepStruct) GoString() string { s = append(s, "Field2: "+fmt.Sprintf("%#v", this.Field2)+",\n") } if this.Field3 != nil { - vs := make([]*NidOptNative, len(this.Field3)) + vs := make([]NidOptNative, len(this.Field3)) for i := range vs { - vs[i] = &this.Field3[i] + vs[i] = this.Field3[i] } s = append(s, "Field3: "+fmt.Sprintf("%#v", vs)+",\n") } if this.Field4 != nil { - vs := make([]*NinOptNative, len(this.Field4)) + vs := make([]NinOptNative, len(this.Field4)) for i := range vs { - vs[i] = &this.Field4[i] + vs[i] = this.Field4[i] } s = append(s, "Field4: "+fmt.Sprintf("%#v", vs)+",\n") } @@ -20818,9 +20818,9 @@ func (this *NidRepStruct) GoString() string { s = append(s, "Field7: "+fmt.Sprintf("%#v", this.Field7)+",\n") } if this.Field8 != nil { - vs := make([]*NidOptNative, len(this.Field8)) + vs := make([]NidOptNative, len(this.Field8)) for i := range vs { - vs[i] = &this.Field8[i] + vs[i] = this.Field8[i] } s = append(s, "Field8: "+fmt.Sprintf("%#v", vs)+",\n") } @@ -20927,9 +20927,9 @@ func (this *NidNestedStruct) GoString() string { s = append(s, "&test.NidNestedStruct{") s = append(s, "Field1: "+strings.Replace(this.Field1.GoString(), `&`, ``, 1)+",\n") if this.Field2 != nil { - vs := make([]*NidRepStruct, len(this.Field2)) + vs := make([]NidRepStruct, len(this.Field2)) for i := range vs { - vs[i] = &this.Field2[i] + vs[i] = this.Field2[i] } s = append(s, "Field2: "+fmt.Sprintf("%#v", vs)+",\n") } diff --git a/test/combos/unmarshaler/thetest.pb.go b/test/combos/unmarshaler/thetest.pb.go index b4f63ae7a2..22b1625a98 100644 --- a/test/combos/unmarshaler/thetest.pb.go +++ b/test/combos/unmarshaler/thetest.pb.go @@ -20187,16 +20187,16 @@ func (this *NidRepStruct) GoString() string { s = append(s, "Field2: "+fmt.Sprintf("%#v", this.Field2)+",\n") } if this.Field3 != nil { - vs := make([]*NidOptNative, len(this.Field3)) + vs := make([]NidOptNative, len(this.Field3)) for i := range vs { - vs[i] = &this.Field3[i] + vs[i] = this.Field3[i] } s = append(s, "Field3: "+fmt.Sprintf("%#v", vs)+",\n") } if this.Field4 != nil { - vs := make([]*NinOptNative, len(this.Field4)) + vs := make([]NinOptNative, len(this.Field4)) for i := range vs { - vs[i] = &this.Field4[i] + vs[i] = this.Field4[i] } s = append(s, "Field4: "+fmt.Sprintf("%#v", vs)+",\n") } @@ -20207,9 +20207,9 @@ func (this *NidRepStruct) GoString() string { s = append(s, "Field7: "+fmt.Sprintf("%#v", this.Field7)+",\n") } if this.Field8 != nil { - vs := make([]*NidOptNative, len(this.Field8)) + vs := make([]NidOptNative, len(this.Field8)) for i := range vs { - vs[i] = &this.Field8[i] + vs[i] = this.Field8[i] } s = append(s, "Field8: "+fmt.Sprintf("%#v", vs)+",\n") } @@ -20316,9 +20316,9 @@ func (this *NidNestedStruct) GoString() string { s = append(s, "&test.NidNestedStruct{") s = append(s, "Field1: "+strings.Replace(this.Field1.GoString(), `&`, ``, 1)+",\n") if this.Field2 != nil { - vs := make([]*NidRepStruct, len(this.Field2)) + vs := make([]NidRepStruct, len(this.Field2)) for i := range vs { - vs[i] = &this.Field2[i] + vs[i] = this.Field2[i] } s = append(s, "Field2: "+fmt.Sprintf("%#v", vs)+",\n") } diff --git a/test/issue630/Makefile b/test/issue630/Makefile new file mode 100644 index 0000000000..377eb61bd0 --- /dev/null +++ b/test/issue630/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../protobuf/:../../../../../:. --gogo_out=. issue630.proto) diff --git a/test/issue630/issue630.pb.go b/test/issue630/issue630.pb.go new file mode 100644 index 0000000000..c5c51131b4 --- /dev/null +++ b/test/issue630/issue630.pb.go @@ -0,0 +1,216 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: issue630.proto + +package issue630 + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + math "math" + reflect "reflect" + strings "strings" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type Foo struct { + Bar1 []Bar `protobuf:"bytes,1,rep,name=Bar1" json:"Bar1"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Foo) Reset() { *m = Foo{} } +func (m *Foo) String() string { return proto.CompactTextString(m) } +func (*Foo) ProtoMessage() {} +func (*Foo) Descriptor() ([]byte, []int) { + return fileDescriptor_60374e06e51d301c, []int{0} +} +func (m *Foo) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Foo.Unmarshal(m, b) +} +func (m *Foo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Foo.Marshal(b, m, deterministic) +} +func (m *Foo) XXX_Merge(src proto.Message) { + xxx_messageInfo_Foo.Merge(m, src) +} +func (m *Foo) XXX_Size() int { + return xxx_messageInfo_Foo.Size(m) +} +func (m *Foo) XXX_DiscardUnknown() { + xxx_messageInfo_Foo.DiscardUnknown(m) +} + +var xxx_messageInfo_Foo proto.InternalMessageInfo + +func (m *Foo) GetBar1() []Bar { + if m != nil { + return m.Bar1 + } + return nil +} + +type Qux struct { + Bar1 []*Bar `protobuf:"bytes,1,rep,name=Bar1" json:"Bar1,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Qux) Reset() { *m = Qux{} } +func (m *Qux) String() string { return proto.CompactTextString(m) } +func (*Qux) ProtoMessage() {} +func (*Qux) Descriptor() ([]byte, []int) { + return fileDescriptor_60374e06e51d301c, []int{1} +} +func (m *Qux) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Qux.Unmarshal(m, b) +} +func (m *Qux) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Qux.Marshal(b, m, deterministic) +} +func (m *Qux) XXX_Merge(src proto.Message) { + xxx_messageInfo_Qux.Merge(m, src) +} +func (m *Qux) XXX_Size() int { + return xxx_messageInfo_Qux.Size(m) +} +func (m *Qux) XXX_DiscardUnknown() { + xxx_messageInfo_Qux.DiscardUnknown(m) +} + +var xxx_messageInfo_Qux proto.InternalMessageInfo + +func (m *Qux) GetBar1() []*Bar { + if m != nil { + return m.Bar1 + } + return nil +} + +type Bar struct { + Baz string `protobuf:"bytes,1,opt,name=Baz" json:"Baz"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Bar) Reset() { *m = Bar{} } +func (m *Bar) String() string { return proto.CompactTextString(m) } +func (*Bar) ProtoMessage() {} +func (*Bar) Descriptor() ([]byte, []int) { + return fileDescriptor_60374e06e51d301c, []int{2} +} +func (m *Bar) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Bar.Unmarshal(m, b) +} +func (m *Bar) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Bar.Marshal(b, m, deterministic) +} +func (m *Bar) XXX_Merge(src proto.Message) { + xxx_messageInfo_Bar.Merge(m, src) +} +func (m *Bar) XXX_Size() int { + return xxx_messageInfo_Bar.Size(m) +} +func (m *Bar) XXX_DiscardUnknown() { + xxx_messageInfo_Bar.DiscardUnknown(m) +} + +var xxx_messageInfo_Bar proto.InternalMessageInfo + +func (m *Bar) GetBaz() string { + if m != nil { + return m.Baz + } + return "" +} + +func init() { + proto.RegisterType((*Foo)(nil), "issue630.Foo") + proto.RegisterType((*Qux)(nil), "issue630.Qux") + proto.RegisterType((*Bar)(nil), "issue630.Bar") +} + +func init() { proto.RegisterFile("issue630.proto", fileDescriptor_60374e06e51d301c) } + +var fileDescriptor_60374e06e51d301c = []byte{ + // 150 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xcb, 0x2c, 0x2e, 0x2e, + 0x4d, 0x35, 0x33, 0x36, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x80, 0xf1, 0xa5, 0x74, + 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0xd3, 0xf3, 0xd3, 0xf3, 0xf5, + 0xc1, 0x0a, 0x92, 0x4a, 0xd3, 0xc0, 0x3c, 0x30, 0x07, 0xcc, 0x82, 0x68, 0x54, 0xd2, 0xe3, 0x62, + 0x76, 0xcb, 0xcf, 0x17, 0x52, 0xe7, 0x62, 0x71, 0x4a, 0x2c, 0x32, 0x94, 0x60, 0x54, 0x60, 0xd6, + 0xe0, 0x36, 0xe2, 0xd5, 0x83, 0x1b, 0xef, 0x94, 0x58, 0xe4, 0xc4, 0x72, 0xe2, 0x9e, 0x3c, 0x43, + 0x10, 0x58, 0x01, 0x48, 0x7d, 0x60, 0x69, 0x05, 0x61, 0xf5, 0x8c, 0x50, 0xf5, 0xb2, 0x5c, 0xcc, + 0x4e, 0x89, 0x45, 0x42, 0x62, 0x20, 0xaa, 0x4a, 0x82, 0x51, 0x81, 0x51, 0x83, 0x13, 0x6a, 0x1e, + 0x48, 0xc0, 0x89, 0xe5, 0xc3, 0x43, 0x39, 0x46, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc9, 0x5d, + 0xa4, 0x14, 0xce, 0x00, 0x00, 0x00, +} + +func (this *Foo) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&issue630.Foo{") + if this.Bar1 != nil { + vs := make([]Bar, len(this.Bar1)) + for i := range vs { + vs[i] = this.Bar1[i] + } + s = append(s, "Bar1: "+fmt.Sprintf("%#v", vs)+",\n") + } + if this.XXX_unrecognized != nil { + s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *Qux) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&issue630.Qux{") + if this.Bar1 != nil { + s = append(s, "Bar1: "+fmt.Sprintf("%#v", this.Bar1)+",\n") + } + if this.XXX_unrecognized != nil { + s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *Bar) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&issue630.Bar{") + s = append(s, "Baz: "+fmt.Sprintf("%#v", this.Baz)+",\n") + if this.XXX_unrecognized != nil { + s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringIssue630(v interface{}, typ string) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) +} diff --git a/test/issue630/issue630.proto b/test/issue630/issue630.proto new file mode 100644 index 0000000000..a991156222 --- /dev/null +++ b/test/issue630/issue630.proto @@ -0,0 +1,47 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package issue630; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.gostring_all) = true; + +message Foo { + repeated Bar Bar1 = 1 [(gogoproto.nullable) = false]; +} + +message Qux { + repeated Bar Bar1 = 1 [(gogoproto.nullable) = true]; +} + +message Bar { + optional string Baz = 1 [(gogoproto.nullable) = false]; +} diff --git a/test/issue630/issue630_test.go b/test/issue630/issue630_test.go new file mode 100644 index 0000000000..db7598e92f --- /dev/null +++ b/test/issue630/issue630_test.go @@ -0,0 +1,55 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package issue630 + +import ( + "testing" +) + +func TestRepeatedNonNullableGoString(t *testing.T) { + foo := &Foo{Bar1: []Bar{{Baz: "a"}, {Baz: "b"}}} + expected := `&issue630.Foo{Bar1: []issue630.Bar{issue630.Bar{Baz:"a", XXX_NoUnkeyedLiteral:struct {}{}, XXX_unrecognized:[]uint8(nil), XXX_sizecache:0}, issue630.Bar{Baz:"b", XXX_NoUnkeyedLiteral:struct {}{}, XXX_unrecognized:[]uint8(nil), XXX_sizecache:0}}, +}` + actual := foo.GoString() + if expected != actual { + t.Fatalf("expected:\n%s\ngot:\n%s\n", expected, actual) + } +} + +func TestRepeatedNullableGoString(t *testing.T) { + qux := &Qux{Bar1: []*Bar{{Baz: "a"}, {Baz: "b"}}} + expected := `&issue630.Qux{Bar1: []*issue630.Bar{&issue630.Bar{Baz: "a", +}, &issue630.Bar{Baz: "b", +}}, +}` + actual := qux.GoString() + if expected != actual { + t.Fatalf("expected:\n%s\ngot:\n%s\n", expected, actual) + } +} diff --git a/test/thetest.pb.go b/test/thetest.pb.go index cefb597661..67187fa5ad 100644 --- a/test/thetest.pb.go +++ b/test/thetest.pb.go @@ -20184,16 +20184,16 @@ func (this *NidRepStruct) GoString() string { s = append(s, "Field2: "+fmt.Sprintf("%#v", this.Field2)+",\n") } if this.Field3 != nil { - vs := make([]*NidOptNative, len(this.Field3)) + vs := make([]NidOptNative, len(this.Field3)) for i := range vs { - vs[i] = &this.Field3[i] + vs[i] = this.Field3[i] } s = append(s, "Field3: "+fmt.Sprintf("%#v", vs)+",\n") } if this.Field4 != nil { - vs := make([]*NinOptNative, len(this.Field4)) + vs := make([]NinOptNative, len(this.Field4)) for i := range vs { - vs[i] = &this.Field4[i] + vs[i] = this.Field4[i] } s = append(s, "Field4: "+fmt.Sprintf("%#v", vs)+",\n") } @@ -20204,9 +20204,9 @@ func (this *NidRepStruct) GoString() string { s = append(s, "Field7: "+fmt.Sprintf("%#v", this.Field7)+",\n") } if this.Field8 != nil { - vs := make([]*NidOptNative, len(this.Field8)) + vs := make([]NidOptNative, len(this.Field8)) for i := range vs { - vs[i] = &this.Field8[i] + vs[i] = this.Field8[i] } s = append(s, "Field8: "+fmt.Sprintf("%#v", vs)+",\n") } @@ -20313,9 +20313,9 @@ func (this *NidNestedStruct) GoString() string { s = append(s, "&test.NidNestedStruct{") s = append(s, "Field1: "+strings.Replace(this.Field1.GoString(), `&`, ``, 1)+",\n") if this.Field2 != nil { - vs := make([]*NidRepStruct, len(this.Field2)) + vs := make([]NidRepStruct, len(this.Field2)) for i := range vs { - vs[i] = &this.Field2[i] + vs[i] = this.Field2[i] } s = append(s, "Field2: "+fmt.Sprintf("%#v", vs)+",\n") }