https://kotlinlang.org logo
#ksp
Title
# ksp
j

jean

01/27/2023, 9:03 PM
I have this annotation :
Copy code
@Target(AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.SOURCE)
annotation class MyAnnotation(val myArgument: Boolean = false)
...
@MyAnnotation
val someVariable1: String

@MyAnnotation(myArgument = true)
val someVariable2: String
...
When I checked the value of the argument, I get
null
instead of
false
Copy code
val argumentValue = someVariable.annotations.first().arguments
logger.warn("${someVariable.simpleName.asString()} argumentValue: $argumentValue"")
...
w: [ksp] someVariable1 argumentValue: [myArgument:null]
w: [ksp] someVariable2 argumentValue: [myArgument:true]
Is that expected?
t

Ting-Yuan Huang

01/27/2023, 10:19 PM
Looks like a bug to me. May I know the exact version of KSP? @Jiaxiang WDYT?
j

Jiaxiang

01/27/2023, 10:39 PM
it’s also worth mentioning if you are building on a non jvm target, there is a known issue with non jvm platform annotation argument default value.
j

jean

01/30/2023, 7:57 AM
Copy code
kotlinVersion=1.8.0
kspVersion=1.8.0-1.0.8
It’s a kotlin multiplatform project but the issue occurs in a unit test on the jvm
10 Views