This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Provide an API to set TypeVariableName bounds lazily #842
Comments
You can use a
|
Thanks for the tip. Unfortunately, this happens at a lower layer. We have some wrapper around KSP - KSType (kotlin symbol processing) and JavaAP-TypeMirror both of which provide an API to get a |
copybara-service bot
pushed a commit
to androidx/androidx
that referenced
this issue
Jun 9, 2021
This CL fixes (a.k.a hacks) an issue in TypeName generation logic in the KSP pipeline where we would go into an infinite loop if we are trying to create TypeName for a self referencing type, e.g.: class SelfReferencing<T : SelfReferencing<T>> JavaPoet solves this using an internal constructor in TypeVariableName and changing bounds after it is created. For this reason, we are also finding that constructor now and using it to construct a TypeVariableName reflectively. square/javapoet#842 Unfortunately, this fix hits a bug in KSP. google/ksp#476 I kept the test where it expects the Error class so we know when it is fixed. Also, there is still saddle differences between KAPT and KSP. More specifically, KAPT might generate wildcard type parameters due to variance. We do that at code generation phase and doing it in typename creation is fairly complicated (a.k.a. i couldn't find an easy way). This does not really matter much so I'm keeping them separate for now. I've also changed compilation test capabilities to only consider kotlin major-minor versions as KSP is more stable now and we should try to avoid disabling it. Bug: 187572913 Test: XTypeTest Change-Id: I9d85f999cd9ec976149dad961b6e94154dde8c16
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Currently, there is no way to set bounds of a TypeVariableName after it is constructed (which makes sense as they are designed to be immutable).
Unfortunately, creating
TypeName
for self referencing types becomes impossible without it (class SelfReferencing<T : SelfReferencing<T>>
)JavaPoet solves this problem internally by using a private constructor:
https://github.com/square/javapoet/blame/master/src/main/java/com/squareup/javapoet/TypeVariableName.java#L108
Would it be possible to open up a builder that receives a List (and keeps it as is) so we can implement the same workaround for KSP ?
For reference, here is the WIP CL in Room where we are trying to workaround this issue. Unfortunately, the only solution we have is reflection which does not feel great.
The text was updated successfully, but these errors were encountered: