Skip to content

Commit

Permalink
Visit field types of messages even if a type should not be generated (#…
Browse files Browse the repository at this point in the history
…336)

Signed-off-by: Miguel Molina <[email protected]>
  • Loading branch information
erizocosmico authored and awalterschulze committed Sep 27, 2017
1 parent 2adc21f commit f7f1376
Show file tree
Hide file tree
Showing 8 changed files with 827 additions and 0 deletions.
9 changes: 9 additions & 0 deletions protoc-gen-gogo/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2210,6 +2210,15 @@ func (g *Generator) generateMessage(message *Descriptor) {
}
g.Out()
g.P("}")
} else {
// Even if the type does not need to be generated, we need to iterate
// over all its fields to be able to mark as used any imported types
// used by those fields.
for _, field := range message.Field {
if !gogoproto.IsStdTime(field) && !gogoproto.IsStdDuration(field) {
g.RecordTypeUse(field.GetTypeName())
}
}
}

// Update g.Buffer to list valid oneof types.
Expand Down
4 changes: 4 additions & 0 deletions test/typedeclimport/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
regenerate:
go install github.com/gogo/protobuf/protoc-gen-gogo
protoc-min-version --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. typedeclimport.proto
protoc-min-version --version="3.0.0" --gogo_out=. --proto_path=../../../../../:../../protobuf/:. ./subpkg/subpkg.proto
7 changes: 7 additions & 0 deletions test/typedeclimport/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package typedeclimport

import subpkg "github.com/gogo/protobuf/test/typedeclimport/subpkg"

type SomeMessage struct {
Imported subpkg.AnotherMessage
}
Loading

0 comments on commit f7f1376

Please sign in to comment.