Skip to content

codegen: check message and enum names against service-derived items #330

Description

@iainmcgin

In connectrpc-build output a package's messages and enums share a Rust module with its service stubs. check_module_collisions (#280) compares the identifiers derived from one service with those derived from another, and does not look at message or enum names. A message named like a service-derived item is accepted at generation time, and the generated code then fails to compile:

service Greet {
  rpc Say(SayRequest) returns (SayResponse);
}
message GreetClient {}
error[E0428]: the name `GreetClient` is defined multiple times

The types a service Greet derives are Greet, GreetExt, GreetServer, GreetClient and GreetRegisterMarker. Its constants are values, which a message or enum does not collide with. The Owned<Message>View aliases are types in the same module, so message OwnedSayRequestView collides with the alias for SayRequest; the alias check from #77 compares aliases with each other only.

The split layout (buf generate with separate proto and connect trees) is not affected, because messages are in a different module there.

Proposed: before the per-service pass, record the package's top-level message and enum names in BatchState::module_idents, so that the existing check reports the pair with both proto names, as it does for two services. Only the unified layout needs it.

#329 documents the limit in docs/guide.md; the fix removes that sentence.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions