Generics question with KProperty1

I have the following function:

class Query<T: Any> {
	fun <P> whereEqualTo(property: KProperty1<T, P>, value: P): Query<T> {
		// ...

I have naively expected that I couldn’t pass any value for value, only those that can be assigned to the property in question (even though I’m not actually assigning it, just building a query).

But this is not true:

data class X(val x: String)

query.whereEqualTo(X::x, 42)

This compiles no problem, because P is substituted with Any.

Is there any way to make it work the way I want?

Thank you


fun <P, V : P> whereEqualTo(property: KProperty1<T, P>, value: V): Query<T>


Found some discussion around this:

Hope this will get fixed in 1.4