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

Using reserved keyword for parameter generates an invalid data class #1035

Closed
ansman opened this issue Jan 19, 2021 · 3 comments
Closed

Using reserved keyword for parameter generates an invalid data class #1035

ansman opened this issue Jan 19, 2021 · 3 comments
Labels
Milestone

Comments

@ansman
Copy link
Contributor

ansman commented Jan 19, 2021

I'm trying to generate a data class that contains a property named data:

val parameter = ParameterSpec.builder("data", STRING).build()

TypeSpec.classBuilder("Example")
  .addModifiers(KModifier.DATA)
  .primaryConstructor(FunSpec.constructorBuilder()
    .addParameter(parameter)
    .build())
  .addProperty(PropertySpec.builder(parameter.name, STRING)
    .initializer("%N", parameter)
    .build()
  .build()

The output does not compile however:

public data class Example(
  `data`: String
) {
  public val data: String = `data`
}
@Egorand
Copy link
Collaborator

Egorand commented Jan 19, 2021

Any specific reason you'd want to use %N in the initializer? If I change that part to initializer(parameter.name) it all works fine.

@ansman
Copy link
Contributor Author

ansman commented Jan 19, 2021

I just figured it was better to not pass unknown input as as format string

@Egorand Egorand added the bug label Feb 27, 2021
@Egorand Egorand modified the milestones: Backlog, 1.11 Feb 20, 2022
@Egorand Egorand modified the milestones: 1.11, Backlog May 14, 2022
Egorand added a commit that referenced this issue May 14, 2022
@Egorand
Copy link
Collaborator

Egorand commented May 14, 2022

I just retested this and the output I see is the following, which looks fine to me:

public data class Example(
  public val `data`: kotlin.String,
)

I added a regression test (#1250) and will close this issue, but please let me know if there's anything I'm missing or if there's anything else to be done here.

@Egorand Egorand closed this as completed May 14, 2022
Egorand added a commit that referenced this issue May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants