Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of "Self" in stripped enum variants #997

Closed
MixusMinimax opened this issue Mar 10, 2024 · 2 comments · Fixed by #998
Closed

Use of "Self" in stripped enum variants #997

MixusMinimax opened this issue Mar 10, 2024 · 2 comments · Fixed by #998

Comments

@MixusMinimax
Copy link
Contributor

Version: 0.12.3

Problem:

Generated enum variants are only sanitized for "Self", if prefix-stripping is not used, or does not apply.

Minimal reproducable protobuf defininition:

enum Feeding {
  FEEDING_UNSPECIFIED = 0;
  FEEDING_ASSISTED = 1;
  // Careful: code generation resulted in "Self".
  FEEDING_SELF = 2;
}

Reason:

The existing code does this:

  1. convert FEEDING_SELF into FeedingSelf
  2. sanitize if that equals Self to replace with Self_
  3. if prefix stripping is enabled:
    1. Extracts the type name, in this case Feeding
    2. convert Feeding to Feeding
    3. sanitize if that equals Self to replace with Self_
    4. Remove the prefix Feeding from FeedingSelf, resulting in Self

The final result is Self, which is not sanitized after.

@MixusMinimax
Copy link
Contributor Author

MixusMinimax commented Mar 10, 2024

The logic is already described in #179, the only missing cases are enum variants after prefix stripping.

@MixusMinimax
Copy link
Contributor Author

I have created a pull request at #998!

github-merge-queue bot pushed a commit that referenced this issue Apr 9, 2024
* Address #997: handle keyword `Self` after stripping enum type prefix

* create sanitize_identifier

* add to_snake back (i did it in two commits to not mess up the git blame)

* small fixes

* add test_sanitize_identifier

* remove unnecessary comment

* combine test_strip_enum_prefix and test_strip_enum_prefix_resulting_in_keyword

* update enum_keyword_variant.proto

* maybe improve docs of strip_enum_prefix?
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 a pull request may close this issue.

1 participant