Why `kotlinc` generates `somePropertyName$annotati...
# announcements
m
Why
kotlinc
generates
somePropertyName$annotations()
with annotations instead of putting them onto the backing field?..
e
Depends on annotations. Maybe the annotation is not applicable to a field? Can you give an example?
m
@[JvmField JvmSynthetic PublishedApi] internal val
->
Copy code
// declaration: (...)
public final static synthetic (...)
@Lkotlin/jvm/JvmField;() // invisible
@Lorg/jetbrains/annotations/NotNull;() // invisible

// DEPRECATED
// access flags 0x21009
public static synthetic PROP$annotations()V
@Lkotlin/PublishedApi;() // invisible
  RETURN
  MAXSTACK = 0
  MAXLOCALS = 0
Copy code
@Volatile @Suppress("UNUSED")
private var valueRef: T = unset()
->
Copy code
// access flags 0x42
// signature TT;
// declaration: T
private volatile Ljava/lang/Object; valueRef

// DEPRECATED
// access flags 0x2100A
private static synthetic valueRef$annotations()V
  RETURN
  MAXSTACK = 0
  MAXLOCALS = 0
o
There is no such entity in JVM as “property”, so all annotations on properties that should be accessible in runtime via Kotlin Reflection should live somewhere. Hence synthetic entity to attach them to.
m
Okay, looks reasonable to put all Kotlin PROPERTY annotations on a special method, avoiding different handling when there's no backing field, no getter, etc. But why it's being generated for
@Volatile @Suppress
which both have
SOURCE
retention? And why
prop$annotations()
functions are marked as deprecated?
o
I think this belongs to #C0AVAB92L, I don’t know the details.