Skip to content

Proto emitter: @field numbers collide when using model inheritance #9278

@vane-tec

Description

@vane-tec

When using the Protobuf emitter, @field(n) is mandatory.

However, when a model extends another model, field numbers are not
merged or offset. This leads to duplicated field numbers in the
generated message, which is invalid in Protobuf.

Example:

model Base {
@field(1)
id: string;
}

model Child extends Base {
@field(1)
name: string;
}

Generated proto:

message Child {
string id = 1;
string name = 1; // invalid: duplicate field number
}

This makes model inheritance unsafe with Protobuf.

Current issues:

  • @field numbers are scoped per model, not per message
  • No validation or error is raised
  • No automatic offset or merging strategy exists

This breaks:

  • Protobuf constraints
  • Backward compatibility guarantees
  • Design-first modeling with inheritance

Suggested directions:

  • Automatically shift child field numbers after inherited fields
  • Or support an implicit field numbering strategy
  • Or disallow inheritance for proto models with a clear error

At the moment, using inheritance with Protobuf is dangerous and
non-deterministic.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions