Skip to content

Commit f06decb

Browse files
committed
process the ast.MapType node as is. close #16
1 parent 8767801 commit f06decb

File tree

6 files changed

+170
-1
lines changed

6 files changed

+170
-1
lines changed

processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func (c *processor) processInner(expr ast.Expr) {
218218
c.write("*")
219219
c.processInner(x.X)
220220

221-
case *ast.CompositeLit, *ast.TypeAssertExpr, *ast.ArrayType, *ast.FuncLit, *ast.SliceExpr:
221+
case *ast.CompositeLit, *ast.TypeAssertExpr, *ast.ArrayType, *ast.FuncLit, *ast.SliceExpr, *ast.MapType:
222222
// Process the node as is.
223223
c.write(formatNode(x))
224224

testdata/proto/test_edition_2023.pb.go

Lines changed: 139 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
edition = "2023";
2+
3+
option go_package = "github.com/ghostiam/protogetter/testdata/proto";
4+
5+
import "google/protobuf/go_features.proto";
6+
option features.(pb.go).api_level = API_OPAQUE;
7+
8+
message TestEdition2023 {
9+
map<string, string> value = 1;
10+
}

testdata/test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ func testInvalid(t *proto.Test) {
9999
t.Map = map[string]string{}
100100
t.GetEmbedded().SetMap(t.Map) // want `avoid direct access to proto field t\.GetEmbedded\(\)\.SetMap\(t\.Map\), use t\.GetEmbedded\(\).SetMap\(t.GetMap\(\)\) instead`
101101
t.GetEmbedded().SetMap(t.GetMap())
102+
t.GetEmbedded().SetMap(map[string]string{})
103+
// Issue #16
104+
t.GetEmbedded().SetMap(make(map[string]string, 5))
102105

103106
// Issue #10
104107
_ = many[slicesIndexFunc(many, func(m *proto.Test) bool {

testdata/test.go.golden

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ func testInvalid(t *proto.Test) {
9999
t.Map = map[string]string{}
100100
t.GetEmbedded().SetMap(t.GetMap()) // want `avoid direct access to proto field t\.GetEmbedded\(\)\.SetMap\(t\.Map\), use t\.GetEmbedded\(\).SetMap\(t.GetMap\(\)\) instead`
101101
t.GetEmbedded().SetMap(t.GetMap())
102+
t.GetEmbedded().SetMap(map[string]string{})
103+
// Issue #16
104+
t.GetEmbedded().SetMap(make(map[string]string, 5))
105+
102106

103107
// Issue #10
104108
_ = many[slicesIndexFunc(many, func(m *proto.Test) bool {

testdata/test_edition_2023.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package testdata
2+
3+
import (
4+
"github.com/ghostiam/protogetter/testdata/proto"
5+
)
6+
7+
func testInvalidEdition2023(t *proto.TestEdition2023) {
8+
_ = t.GetValue()
9+
t.SetValue(t.GetValue())
10+
t.SetValue(map[string]string{"test": "test"})
11+
// Issue #16
12+
t.SetValue(make(map[string]string, 5))
13+
}

0 commit comments

Comments
 (0)