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

Kotlin codegen generates invalid code when a parameterized mapped superclass is used #891

Open
1 task done
jpmsilva opened this issue Feb 11, 2025 · 1 comment
Open
1 task done

Comments

@jpmsilva
Copy link

Important Notice

Thank you for opening an issue! Please note that, as outlined in the README, I currently only work on feature requests or bug fixes when sponsored. Balancing this project with professional and personal priorities means I have a very limited amount of effort I can divert to this project.

You must put in the work to address this issue, or it won't be addressed.

  • I am willing to put in the work and submit a PR to resolve this issue.

Describe the bug

When using a parameterized mapped superclass the generated Q-classes are invalid with respect to the generic parameters.

To Reproduce

A test example can be seen at https://github.com/jpmsilva/openfeign-querydsl/tree/kotlin-codegen-generic-supertype (branched from the 6.10.1 release).

Running clean package -P quickbuild from the folder querydsl-examples/querydsl-example-kotlin-codegen shows the issue:

[INFO] --- kotlin:2.1.0:compile (compile) @ querydsl-example-kotlin-codegen ---
[INFO] Applied plugin: 'jpa'
[WARNING] Duplicate source root: querydsl/querydsl-examples/querydsl-example-kotlin-codegen/target/generated-sources/kapt/compile
[WARNING] Duplicate source root: querydsl/querydsl-examples/querydsl-example-kotlin-codegen/target/generated-sources/kaptKotlin/compile
[ERROR] querydsl/querydsl-examples/querydsl-example-kotlin-codegen/target/generated-sources/kaptKotlin/compile/com/querydsl/examples/kotlin/entity/QExampleBaseEntity.kt: (23, 42) None of the following candidates is applicable:
constructor<T : Any!>(p0: Class<out T!>!, p1: String!): EntityPathBase<T>
constructor<T : Any!>(p0: Class<out T!>!, p1: PathMetadata!): EntityPathBase<T>
[ERROR] querydsl/querydsl-examples/querydsl-example-kotlin-codegen/target/generated-sources/kaptKotlin/compile/com/querydsl/examples/kotlin/entity/QExampleBaseEntity.kt: (27, 48) None of the following candidates is applicable:
constructor<T : Any!>(p0: Class<out T!>!, p1: String!): EntityPathBase<T>
constructor<T : Any!>(p0: Class<out T!>!, p1: PathMetadata!): EntityPathBase<T>
[ERROR] querydsl/querydsl-examples/querydsl-example-kotlin-codegen/target/generated-sources/kaptKotlin/compile/com/querydsl/examples/kotlin/entity/QExampleEntity.kt: (27, 5) None of the following candidates is applicable:
constructor(variable: String): QExampleBaseEntity
constructor(path: Path<out ExampleBaseEntity<Serializable>>): QExampleBaseEntity
constructor(metadata: PathMetadata): QExampleBaseEntity

Expected behavior
Build should complete without errors.

Screenshots
N/A

Desktop (please complete the following information):
N/A

Smartphone (please complete the following information):
N/A

Additional context
I might be able to submit a PR to properly set the out keyword in the superclass parameters of the generated Q-classes. This aligns the generated Kotlin Q-classes with the Java Q-classes with regards to entity parameters, when they are used.

When using the Java codegen variant these generic mapped superclass types are properly handled. The issue only happens in the Kotlin codegen module.

@jpmsilva
Copy link
Author

Please note that I also tested the same scenario using the KSP codegen, but it results in a different error. Unfortunately I am not able to properly diagnose that issue, as KSP is not something I know how to work with:

e: [ksp] java.lang.IllegalStateException: Error processing com.querydsl.example.ksp.BaseEntity.id: Type was not recognised, This may be an entity that has not been annotated with @Entity, or maybe you are using javax instead of jakarta.

Do let me know if you'd like a separate issue filed for the KSP codegen issue, but please take note that I won't be able to assist in that case.

jpmsilva added a commit to jpmsilva/openfeign-querydsl that referenced this issue Feb 11, 2025
jpmsilva added a commit to jpmsilva/openfeign-querydsl that referenced this issue Feb 11, 2025
jpmsilva added a commit to jpmsilva/openfeign-querydsl that referenced this issue Feb 11, 2025
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

No branches or pull requests

1 participant