So I have been playing around with K2 compiler plu...
# compiler
g
So I have been playing around with K2 compiler plugins and I was wondering how I can get the type of a class member property that's type is dependent on a type parameter when I have a
ConeClassLikeType
that has been created within a session and an array of type arguments.
Copy code
parent.declarationSymbols.filterIsInstance<FirPropertySymbol>().forEach {
  valueParameter(it.name, {typeArgs ->
    val type = parent.classId.createConeType(
      session,
      typeArgs.map { it.symbol.toConeType() }.toTypedArray(),
      nullable = false
    )
    
    type.createConeTypeOfMember(session, it.name)      //  <<<----------- Ideally I want something like the following
  })
}
If you are wondering what I am trying to accomplish, I would like it so that an interface will automatically have a companion object with an
invoke
function that has a parameter for every
val
property it or it's super types declare and then returns an instance of the interface. I am struggling to get the types of properties that are constrained by generics to be constrained by the
invoke
function's corresponding type parameters. Such that the following:
Copy code
interface Foo<V>{
  val foo: List<V>
}

interface Bar<T>: Foo<Set<T>>{
  val bar: T
  val tan: Int
}
Will result in:
Copy code
interface Foo<V>{
  companion object{
    operator fun <V> invoke(foo: List<V>): Foo<V> = TODO()
  }
  val foo: List<V>
}

interface Bar<T>: Foo<Set<T>>{
  companion object{
    operator fun <T> invoke(bar: T, tan: Int, foo: List<Set<T>>): Bar<V> = TODO()
  }
  val bar: T
  val tan: Int
}
j
you need to use
substitutorByMap
g
Thank you!