tapioca icon indicating copy to clipboard operation
tapioca copied to clipboard

Many protubuf dsl fixes

Open slinkp opened this issue 3 years ago • 0 comments

Motivation

I will probably abandon this and pull bits of it into smaller PRs after #966 merges

Generated RBIs differ in many ways from the ruby protobuf documentation and the code actually generated by protoc. Attempting to fix as many of them as possible.

Ignore spurious gemfile & version bumps - will revert those

Rebase badly needed

  • [x] All parameters to #initialize should actually be nilable
  • [x] Per docs: Readers for fields of :message type can return nil. Setters for fields of :message type can accept nil. Primitive field types (string et al) can't be assigned nor return nil. (But see the previous point - you can still pass nil to #initialize)
  • [x] There's a generated clear_foo method for all fields, was missing.
  • [x] :enum fields can accept or return Integer or Symbol per the docs.
  • [ ] TODO: there's a missing type declaration for Enum values. I've seen these shimmed like FOO = type_alias(T.untyped) but maybe should be FOO = type_alias(T.any(Integer, Symbol)) ?
  • [ ] TODO: The docs say there should be a has_foo? generated method for all non-repeated fields, but it doesn't seem to actually exist 🤔 ... maybe a more recent version of protoc than I have?
  • [ ] TODO: per the docs there are module methods on Enums: #lookup, #resolve, #descriptor and we are missing declarations for those

Implementation

Building on top of Ray's make_protobuf_signature_nilable PR

The code with my changes is getting a bit hard to follow and could use some OO refactoring. In particular, the handling of repeated and map fields is not consistent with the others. In current state, i mainly wanted to see if I could get something working and confirm the RBI output.

Tests

Yes, following the existing approach. However, we are lacking tests that the generated sigs actually work as intended

slinkp avatar May 24 '22 14:05 slinkp