Skip to content

fix(core): use backtick-escaped constant reference for enum default values#99

Merged
mfabisiak merged 1 commit into
masterfrom
fix/backtick-escape-enum-constant-names-in-generated-default-values
Jun 19, 2026
Merged

fix(core): use backtick-escaped constant reference for enum default values#99
mfabisiak merged 1 commit into
masterfrom
fix/backtick-escape-enum-constant-names-in-generated-default-values

Conversation

@mfabisiak

Copy link
Copy Markdown
Member

When an enum value produces a constant name that is not a valid Kotlin
identifier (e.g. "1" → 1), the generated default value was emitted
without backticks, causing a compilation error:

data class Request(
    val floor: Floor = Floor.1  // invalid
)

Using %N instead of %L in KotlinPoet's CodeBlock lets the library
apply backtick escaping automatically:

data class Request(
    val floor: Floor = Floor.`1`  // correct
)

Adds a regression test covering a numeric-string enum default.

@mfabisiak mfabisiak self-assigned this Jun 19, 2026
Copilot AI review requested due to automatic review settings June 19, 2026 11:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Kotlin model generation for enum-valued defaults when the generated enum constant name is not a valid Kotlin identifier (e.g., "1"), ensuring KotlinPoet emits a backtick-escaped constant reference so generated code compiles.

Changes:

  • Switch enum default-value emission from KotlinPoet’s %L to %N so invalid identifiers get backtick-escaped automatically.
  • Add a regression test that asserts numeric-string enum defaults produce backtick-escaped references.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
core/src/main/kotlin/com/avsystem/justworks/core/gen/model/ModelGenerator.kt Uses %N for enum constant references in default values to trigger KotlinPoet escaping.
core/src/test/kotlin/com/avsystem/justworks/core/gen/ModelGeneratorTest.kt Adds a regression test for a numeric-string enum default value to prevent reintroducing the compile error.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

Copy link
Copy Markdown

Coverage Report

Overall Project 96.53% 🍏
Files changed 100% 🍏

File Coverage
ModelGenerator.kt 96.2% 🍏

@mfabisiak mfabisiak merged commit a8bb997 into master Jun 19, 2026
2 checks passed
@mfabisiak mfabisiak deleted the fix/backtick-escape-enum-constant-names-in-generated-default-values branch June 19, 2026 12:10
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