Hello everyone,I want to add a new property to a ...
# compiler
m
Hello everyone,I want to add a new property to a class named "mjd", I can see the property after using dump() function (in the bottom of the following result).But when I test this compiler plugin, it can not find this new property. Does anyone know the reason? CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any] annotations: DebugLog $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.A CONSTRUCTOR visibility:public <> () returnType:<root>.A [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any' INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any $this: VALUE_PARAMETER name:<this> type:kotlin.Any VALUE_PARAMETER name:other index:0 type:kotlin.Any? FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] overridden: public open fun hashCode (): kotlin.Int declared in kotlin.Any $this: VALUE_PARAMETER name:<this> type:kotlin.Any FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] overridden: public open fun toString (): kotlin.String declared in kotlin.Any $this: VALUE_PARAMETER name:<this> type:kotlin.Any FUN name:track visibility:public modality:OPEN <> ($this:<root>.A) returnType:kotlin.String $this: VALUE_PARAMETER name:<this> type:<root>.A PROPERTY name:mjd visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:mjd type:kotlin.Long? visibility:private EXPRESSION_BODY CONST Long type=kotlin.Long value=1 FUN DEFAULT_PROPERTY_ACCESSOR name:<get-mjd> visibility:public modality:FINAL <> ($this:<root>.A) returnType:kotlin.Long? correspondingProperty: PROPERTY name:mjd visibility:public modality:FINAL [val] $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.A BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun <get-mjd> (): kotlin.Long? declared in <root>.A' GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:mjd type:kotlin.Long? visibility:private' type=kotlin.Long? origin=null receiver: GET_VAR '<this>: <root>.A declared in <root>.A.<get-mjd>' type=<root>.A origin=null
🧵 2
n
What do you mean by it can't find this property?
m
the error occurs: unresolved reference: mjd
n
AFAIR if your function will be called from source code, on top of the IR generation, you should also declare it in the compiler frontend phase. Not sure what’s the best extension for that
m
Do you mean I should declare the new property or function in the SyntheticResolveExtension first, then implement it in IrElementTransformerVoidWithContext?
n
Yeah, that's what I would try.