Skip to content

Conversation

@araysse
Copy link

@araysse araysse commented Dec 24, 2025

Root Cause

When using @wither and @builder annotations together on nested records (records defined inside a class), the generated wither interface incorrectly references the builder class name, causing compilation errors.

Approach

  • Derive the builder’s package from the binary name (the string with $ for inner classes), not the canonical name.

  • Compute the package as the substring of recordType.getName() up to the last '.'.

  • Build the builder simple name using the binary part if the record is inner:

    • If inner: FooBarBuilder
    • Else: FooBuilder
  • Compose the final FQN as:

    • builderClassName = pkg.isEmpty() ? builderSimpleName : pkg + "." + builderSimpleName
  • Preserve generics by using TypeDef.parameterized when the record type is parameterized.

Verification

  • Reproduced failure with a nested record using both annotations; after applying the change, build succeeds.

Closes: #366

@araysse araysse changed the title Fix Wither builder type resolution for nested records Fix Wither builder type resolution for nested records fix #366 Dec 24, 2025
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 New Critical Issues (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@araysse araysse requested review from dstepanov and sdelamo December 24, 2025 10:44
@dstepanov
Copy link
Collaborator

Please add a test that is reproducing this problem

@dstepanov
Copy link
Collaborator

Why did you add JVM_17?

Copy link
Contributor

@sdelamo sdelamo left a comment

Choose a reason for hiding this comment

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

The pull request misses tests. Is there an issue this PR aims to fix?

araysse and others added 2 commits December 30, 2025 21:09
Co-authored-by: Sergio del Amo <sergio.delamo@softamo.com>
Co-authored-by: Sergio del Amo <sergio.delamo@softamo.com>
@araysse
Copy link
Author

araysse commented Dec 30, 2025

Why did you add JVM_17?

i just need to make the build pass because i was have
Inconsistent JVM-target compatibility detected for tasks 'compileJava' (17) and 'compileKotlin' (21).
this pr fix the issue #366

# Conflicts:
#	sourcegen-generator-kotlin/build.gradle.kts
#	test-suite-kotlin/build.gradle.kts
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.

4 participants