https://kotlinlang.org logo
#compiler
Title
# compiler
a

Ayla

11/16/2023, 4:26 PM
Hello, I want to change the type of the annotated function, and then I discovered a difficulty. After I changed it, all types associated with it must be modified.
Copy code
fun function(){
  val lambda=@Annotaed {}
  val lambdaList=listOf(lambda)
}
Assuming that
@Annotated
will change the type
()->Unit
to
(Node)->Unit
, then the type of the variable
lambda
,
lambdaList
, and the generic parameter type of
listOf
all need to be modified. However, it is obviously not a good idea to manually traverse and modify all the places where it may be used when an annotated function is found. Any idea if there is some mechanism or utils to achieve this? I know compose does this job very well, although I don't understand how.
i

Icyrockton

11/18/2023, 1:32 AM
I think you still need to manually traverse these different IRs to modify them, just like in compose https://android.googlesource.com/platform/frameworks/support/+/7a7fa5271d841bcebe637e0dc8[…]/compiler/plugins/kotlin/lower/ComposableTypeRemapper.kt
a

Ayla

11/18/2023, 5:12 AM
Got it, thank you!