Skip to content

Conversation

@britto
Copy link
Collaborator

@britto britto commented Oct 16, 2021

Scalars were no longer getting wrapped in brackets since #140 (See #173), now they are. Also add parentheses to remote type calls with no arguments (.t -> .t()).

@britto britto mentioned this pull request Oct 16, 2021
def enum_to_spec(:TYPE_SFIXED64), do: "integer"
def enum_to_spec(:TYPE_SINT32), do: "integer"
def enum_to_spec(:TYPE_SINT64), do: "integer"
def enum_to_spec(_), do: "any"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TYPE_GROUP was the only one missing, added above ☝️. Removing this catch-all clause will make the library more strict (and brittle) in regards to the unknown future. As an alternative, we could add it back but raise a warning instead.

Comment on lines -39 to -42
def enum_to_spec(:TYPE_MESSAGE, type, true = _repeated), do: "[#{type}.t]"
def enum_to_spec(:TYPE_MESSAGE, type, false = _repeated), do: "#{type}.t | nil"
def enum_to_spec(:TYPE_ENUM, type, true = _repeated), do: "[#{type}.t]"
def enum_to_spec(:TYPE_ENUM, type, false = _repeated), do: "#{type}.t"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The label (optional, required or repeated) logic didn't seem to fit well in here, so I moved it up to the caller.

@britto britto force-pushed the fix-repeated-and-optional-typespecs branch from 76b4ed8 to 54f1397 Compare October 16, 2021 02:51
@ericmj
Copy link
Collaborator

ericmj commented Oct 19, 2021

Would it makes sense to review this and #175 after #174 is merged to avoid the unrelated diffs?

@britto
Copy link
Collaborator Author

britto commented Oct 19, 2021

@ericmj Yes, good point, even though this one will revert a few of the changes from #174. Stuff from #175 will apply cleanly anyway.

@britto britto force-pushed the fix-repeated-and-optional-typespecs branch 3 times, most recently from d4f7c42 to 922c823 Compare October 20, 2021 16:23
@britto
Copy link
Collaborator Author

britto commented Oct 20, 2021

Rebased ✅

I'm still having second thoughts about this one though. Everything is optional in proto3, so we're likely to generate a lot of churn when users regenerate their files. Not handling optional field changes for now.

Optional fields types were not including `nil` as a possible value, now they do.
Repeated scalar fields were not getting wrapped in brackets, now they are.
@britto britto force-pushed the fix-repeated-and-optional-typespecs branch from 922c823 to 89e49fb Compare October 20, 2021 20:15
Optional when type is message and required otherwise.
@britto britto changed the title Fix typespec generation for repeated and optional fields Fix typespec generation for repeated fields Oct 21, 2021
@whatyouhide whatyouhide merged commit 098afc7 into elixir-protobuf:master Oct 26, 2021
@whatyouhide
Copy link
Collaborator

Nice job @britto, thanks! 💟

@britto britto deleted the fix-repeated-and-optional-typespecs branch October 26, 2021 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants