-
-
Notifications
You must be signed in to change notification settings - Fork 84
fix(ksp): skip parameterized supertypes in TypeExtractor.fallbackType() #1690
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -65,8 +65,9 @@ class TypeExtractor( | |||||||||||
| Comparable::class.java.canonicalName, | ||||||||||||
| java.lang.Comparable::class.qualifiedName | ||||||||||||
| ) | ||||||||||||
| declaration.getAllSuperTypes().any { | ||||||||||||
| comparableNames.contains(it.toClassName().canonicalName) | ||||||||||||
| declaration.getAllSuperTypes().any { supertype -> | ||||||||||||
| // Skip parameterized types (e.g. Comparable<ObjectId>) — toClassName() throws for them | ||||||||||||
| supertype.arguments.isEmpty() && comparableNames.contains(supertype.toClassName().canonicalName) | ||||||||||||
|
Comment on lines
+69
to
+70
|
||||||||||||
| // Skip parameterized types (e.g. Comparable<ObjectId>) — toClassName() throws for them | |
| supertype.arguments.isEmpty() && comparableNames.contains(supertype.toClassName().canonicalName) | |
| val supertypeDeclaration = supertype.declaration as? KSClassDeclaration | |
| val qualifiedName = supertypeDeclaration?.qualifiedName?.asString() | |
| comparableNames.contains(qualifiedName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
supertype.arguments.isEmpty()guard preventsComparable<T>(which is almost always parameterized) from ever being recognized as comparable. That avoids the crash, but it also changes behavior: types likeObjectId : Comparable<ObjectId>will now be treated asSimpleType.Simple(SimplePath) instead ofSimpleType.Comparable(ComparablePath), likely reducing supported comparison operators.Instead of skipping parameterized supertypes, compare using the supertype declaration (e.g.,
supertype.declaration.qualifiedName?.asString()orsupertype.declaration.toClassName().canonicalName) so you can safely detectComparableregardless of type arguments without callingtoClassName()on theKSTypeitself.