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

KSP returns single value for arrays if array syntax is not used #214

Open
yigit opened this issue Dec 29, 2020 · 2 comments
Open

KSP returns single value for arrays if array syntax is not used #214

yigit opened this issue Dec 29, 2020 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@yigit
Copy link
Collaborator

yigit commented Dec 29, 2020

For the given annotation:

public @interface JavaAnnotationWithTypeReferences {
    Class<?>[] value();
}

And usage:

@JavaAnnotationWithTypeReferences(String.class)
class Subject {
}

Obtaining the annotation value in KSP gives back the String type as a single item instead of list/array of KSType.

annotation.arguments.first is KSType -> true

Note that this does not happen if array syntax is used but it is not mandatory in java.

@JavaAnnotationWithTypeReferences({String.class}) <- List<KSType>
class Subject {
}
copybara-service bot pushed a commit to androidx/androidx that referenced this issue Dec 29, 2020
In java code, if an array value is set without using the array syntax
(e.g. not wrapped in {}), KSP might return it as a single item instead
of a list of items.
google/ksp#214

This CL adds a workaround to assume it when a single item is received
when we are expecting an array and wraps it into a list.

Bug: 176180385
Test: XAnnotationBoxTest.typeReferenceArray_singleItemInJava
Test: TypeAdapterStoreTest.testInvalidNonStaticInnerClass

Change-Id: Ia5d2513f28550eace91831cf9213a046dafae020
@ting-yuan ting-yuan added the duplicate This issue or pull request already exists label Dec 31, 2020
@ting-yuan
Copy link
Collaborator

Looks like the same issue to #172 .

@kuanyingchou
Copy link
Collaborator

Bumped into this and it's still the case with both KSP 1.9.23-1.0.19 and 2.0.0-Beta4-1.0.20-20240404.100110-27.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants