From b53207df90b9856a5380e9b4460d8eed03dbb01b Mon Sep 17 00:00:00 2001 From: Vladislav Fursov Date: Wed, 11 Sep 2024 19:52:38 +0400 Subject: [PATCH] process the `ast.SliceExpr` node as is. close #12 Signed-off-by: Vladislav Fursov --- processor.go | 2 +- testdata/proto/test.go | 4 ++++ testdata/test.go | 4 ++++ testdata/test.go.golden | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/processor.go b/processor.go index eca8293..44f346e 100644 --- a/processor.go +++ b/processor.go @@ -218,7 +218,7 @@ func (c *processor) processInner(expr ast.Expr) { c.write("*") c.processInner(x.X) - case *ast.CompositeLit, *ast.TypeAssertExpr, *ast.ArrayType, *ast.FuncLit: + case *ast.CompositeLit, *ast.TypeAssertExpr, *ast.ArrayType, *ast.FuncLit, *ast.SliceExpr: // Process the node as is. c.write(formatNode(x)) diff --git a/testdata/proto/test.go b/testdata/proto/test.go index e48a033..8dcd3e5 100644 --- a/testdata/proto/test.go +++ b/testdata/proto/test.go @@ -21,3 +21,7 @@ func (x *Embedded) SetS(s string) { func (x *Embedded) SetMap(_ map[string]string) { } + +func (x *Test) MyMarshal([]byte) (int, error) { + return 0, nil +} diff --git a/testdata/test.go b/testdata/test.go index 03efae2..d309132 100644 --- a/testdata/test.go +++ b/testdata/test.go @@ -179,6 +179,10 @@ func testValid(t *proto.Test) { t.RepeatedEmbeddeds = append(t.GetRepeatedEmbeddeds(), t.GetRepeatedEmbeddeds()...) t.RepeatedEmbeddeds = append(t.RepeatedEmbeddeds, t.GetEmbedded()) t.RepeatedEmbeddeds = append(t.RepeatedEmbeddeds, &proto.Embedded{}) + + // issue #12 + data := make([]byte, 4) + _, _ = t.MyMarshal(data[4:]) } // stubs diff --git a/testdata/test.go.golden b/testdata/test.go.golden index 89fb8b9..4adb765 100644 --- a/testdata/test.go.golden +++ b/testdata/test.go.golden @@ -179,6 +179,10 @@ func testValid(t *proto.Test) { t.RepeatedEmbeddeds = append(t.GetRepeatedEmbeddeds(), t.GetRepeatedEmbeddeds()...) t.RepeatedEmbeddeds = append(t.RepeatedEmbeddeds, t.GetEmbedded()) t.RepeatedEmbeddeds = append(t.RepeatedEmbeddeds, &proto.Embedded{}) + + // issue #12 + data := make([]byte, 4) + _, _ = t.MyMarshal(data[4:]) } // stubs