I'm trying to add a synthetic property to classes ...
# compiler
r
I'm trying to add a synthetic property to classes w/ my annotation. It works as expected, except it turns any property access statements on that class into get_fields on the added property's backing field. It does this before it even gets to the IR phase, so I'm not sure what's causing it. The SyntheticResolveExtension is just:
Copy code
class KlairvoyantResolveExtension() : SyntheticResolveExtension {
    override fun generateSyntheticProperties(thisDescriptor: ClassDescriptor, name: Name, bindingContext: BindingContext, fromSupertypes: ArrayList<PropertyDescriptor>, result: MutableSet<PropertyDescriptor>) {
        if (!thisDescriptor.hasWatchAnnotation())
            return

        if(result.any { it.name == Name.identifier(Names.ClassWatcherProp) })
            return

        with(FrontendReferencer(thisDescriptor.module)) {
            val classWatcherDescriptor = SimpleSyntheticPropertyDescriptor(thisDescriptor, Names.ClassWatcherProp, KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, CompositeWatcher, listOf()), visibility = Visibilities.PUBLIC)
            result.add(classWatcherDescriptor)
        }
    }
}
s
I suspect access to any property without a custom getter gets converted to get_fields automatically. Maybe you can add a getter descriptor to your property?
r
yeah, I can, but it shouldn't be referencing that property at all.
test.id
is turning into
get_field(test, custom_field)
. The turning into get_field is fine otherwise. I'm not touching the other properties until the IR phase (and it doesn't get there with this).
I figured it out: I should only be adding my synthetic property when the name matches. Obvious in hindsight. This method is called once per prop not once per class.