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

Escape enum variants to avoid collision with generated Unknown variant #388

Merged
5 commits merged into from May 18, 2021
Merged

Escape enum variants to avoid collision with generated Unknown variant #388

5 commits merged into from May 18, 2021

Conversation

ghost
Copy link

@ghost ghost commented May 17, 2021

This fixes enum variant collisions in #386.

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

Copy link
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

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

LGTM, one suggestion to use a convenience method for tests.

We should generate some docs when we do this but that doesn't need to be in this PR.

string SomeEnum
""".asSmithyModel()

val shape = model.expectShape(ShapeId.from("test#SomeEnum"), StringShape::class.java)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
val shape = model.expectShape(ShapeId.from("test#SomeEnum"), StringShape::class.java)
val shape = model.lookup<StringShape>("test#SomeEnum")

Copy link
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

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

LGTM. Can you sanity check the generated code diff to make sure it looks reasonable before merging?

import java.lang.IllegalStateException

/** Model that wraps [EnumDefinition] to calculate and cache values required to generate the Rust enum source. */
internal class EnumMemberModel(private val definition: EnumDefinition) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[not required] this code would probably be slightly cleaner (and avoid the need for null) if these were constructed after we had already validated that the enum did have names (eg. if the parameters were name: String value:String)

Copy link
Author

Choose a reason for hiding this comment

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

I like the idea. I think this would only save a single null check though since we probably still want to assert the EnumDefinition.name is not null for code correctness. Given that, I'm less inclined to refactor.

private fun RustWriter.docWithNote(doc: String?, note: String?) {
doc?.also { docs(it) }
note?.also {
doc?.also { write("///") }
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add a comment saying the point of this is to create a line break? I originally thought these were the /// before **Note**

Copy link
Author

Choose a reason for hiding this comment

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

For sure.

@ghost
Copy link
Author

ghost commented May 18, 2021

@ghost ghost merged commit 9e05d1f into smithy-lang:main May 18, 2021
This pull request was closed.
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.

2 participants