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

Name collision refactor #492

Merged
merged 5 commits into from
Jun 11, 2021
Merged

Name collision refactor #492

merged 5 commits into from
Jun 11, 2021

Conversation

rcoh
Copy link
Collaborator

@rcoh rcoh commented Jun 11, 2021

Issue #, if available: Fixes #488
Description of changes: A medium sized overhaul of our renaming machinery.

  1. Renaming was centralized to ReservedWordSymbolProvider
  2. Unknown was un-special cased and docs are now generated generically during renames
  3. Support the case where a service defines UnknownValue
  4. Fix integration test which wasn't actually generating this enum.

Generated code from integration test:

pub enum UnknownVariantCollidingEnum {
    Known,
    /// **NOTE:** `::Self` has been renamed to `::SelfValue`.
    SelfValue,
    /// **NOTE:** `::SelfValue` has been renamed to `::SelfValue_`.
    SelfValue_,
    /// **NOTE:** `::Unknown` has been renamed to `::UnknownValue`.
    UnknownValue,
    /// **NOTE:** `::UnknownValue` has been renamed to `::UnknownValue_`.
    UnknownValue_,
    /// Unknown contains new variants that have been added since this code was generated.
    Unknown(String),
}

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@rcoh rcoh requested a review from jdisanti June 11, 2021 14:12
override fun toEnumVariantName(definition: EnumDefinition): MaybeRenamed? {
val baseName = base.toEnumVariantName(definition) ?: return null
if (baseName.renamedFrom != null) {
throw CodegenException("hmm")
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the intent here?

when (sortedMembers.any { it.collidesWithUnknown }) {
true ->
"`$enumName::$UnknownVariant` has been renamed to `::$EscapedUnknownVariant`. " +
"`$enumName::$UnknownVariant` refers to additional values that may have been added since " +
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the Unknown variant have documentation on it indicating what it is?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah added (see description)

@rcoh rcoh requested a review from jdisanti June 11, 2021 18:25
Copy link
Collaborator

@jdisanti jdisanti left a comment

Choose a reason for hiding this comment

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

LGTM!

@rcoh rcoh merged commit a47ada5 into main Jun 11, 2021
@rcoh rcoh deleted the name-collision-refactor branch June 11, 2021 18:53
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.

Self in paths can only be used in start position
2 participants