marcoferrer / kroto-plus

gRPC Kotlin Coroutines, Protobuf DSL, Scripting for Protoc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Naming collision with nested fields

keyserbrian1 opened this issue · comments

I am working on a project that includes the Google pre-built .proto files as explicit files in its proto sources. Kroto-plus works fine in compiling code for most of them (as well as all of our own protos), but comiplation fails when the file .../google/rpc/error_details.proto is included for the protoBuilders generator.

Looking at the generated code, the issue is that objects with the same name as the proto classes are generated which shadow the (imported) classes, so other (generated) code (in the same file) that refers to them by their short names finds the objects instead and breaks.

We've put in a temporary fix of excluding that file, but it would be much more convenient for a proper fix to be available.

Thanks for reporting this issue!
Would you be able to supply a sample of the configuration you're using for the plugin so that I can reproduce the issue? Do have an example of the invalid output?

krotoPlusConfig.yaml

protoBuilders:
  - filter:
      excludePath:
            - google/*
            - [project]/rpc/error_details.proto # A copy of Google's file, for direct access purposes. (It's an older version, but the newer version shows the same problematic areas.)
    unwrapBuilders: true
    useDslMarkers: true
extendableMessages:
  - filter:
      excludePath:
grpcStubExts:
  - supportCoroutines: true
grpcCoroutines:
  - filter:
      excludePath:

If [project]/rpc/error_details.proto is commented out of the exclude, then I get the attached file, which has a large number of "Unresolved reference: xxx" errors when it tries to compile, as well as some "Function invocation XXX expected", "Inline function XXX cannot be recursive" and "No value passed for parameter 'block'" errors.

ErrorDetailsProtoBuilders.kt.txt

When I remove or rename the objects at the bottom of the file, the errors go away.

Also, as a (possibly) related issue, if I comment out the google/* line, I get

Execution failed for task ':generateProto'.
> protoc: stdout: . stderr: [project_dir]/java/src/main/proto: warning: directory does not exist.
  com/google/protobuf/Any.java: Tried to insert into file that doesn't exist.
  com/google/protobuf/Timestamp.java: Tried to insert into file that doesn't exist.
  com/google/protobuf/Struct.java: Tried to insert into file that doesn't exist.
  com/google/protobuf/Value.java: Tried to insert into file that doesn't exist.
  com/google/protobuf/ListValue.java: Tried to insert into file that doesn't exist.
  com/google/protobuf/Duration.java: Tried to insert into file that doesn't exist.

from Gradle.

Awesome. I think I see the issue already. I'll update here with the source of the issue after a bit of investigating.

A PR has been opened outlining my findings and a proposed solution.

Unfortunately there isnt much that can be done to fix the collisions. It seems like the only backwards compatible solution involved introducing checks that prevent the unwraping of objects that would cause collisions.