How do we type-project type arguments of properties?

It all started with this (intentionally) invalid code:

class Box<T>(var item: T)
fun <T> fx(box: Box<T>){ }

fx<Int>(Box(1)) //OK
fx<out Int>(Box(1)) //ERROR

We would receive an error on “out”:

Projections are not allowed on type arguments of functions and properties

Here the attempt to perform covariant projection on the type argument Int, which the related type parameter T is declared by the function, is not allowed.

And so this explains the error message, “projections are not allowed on type arguments of functions”.

 

What got me curious, is the what the error message implies about properties – that we could perform type projection on their arguments.

But how do we perform “projection on type arguments of properties”?

 

This code is not an example of that:

class DummyClassBecauseIAmPuttingThisInLocalScope(
    val prop: Box<out Int>
)

Type projection is performed on the type argument of Box; the property declared no type parameter.
The code is well-formed and it doesn’t trigger the error message above, so we can be sure it is not an example of “projection on type argument of property”.

Next I tried extension properties:

class DummyClassBecauseIAmPuttingThisInLocalScope{
    val <T> T.eprop get() = this.toString()
}

But with this I have no clue how to perform type projection on T.

 

I feel like I had misunderstood something along the way. Any clues? thanks!

https://youtrack.jetbrains.com/issue/KT-64254/Projections-are-not-allowed-on-type-arguments-of-functions-and-properties-Type-project-type-arguments-of-properties