Hi there, I found a bug in the new 1.4 type infere...
# compiler
g
Hi there, I found a bug in the new 1.4 type inference that is going to cause huge headaches for any apps that use MvRx (Airbnb, Dropbox, Netflix, Tonal, Turo, among many others) https://youtrack.jetbrains.com/issue/KT-41135 Have any of you encountered this?
m
Hi, I'll take a look, but at the moment I can't reproduce the problem, maybe there's an error in the example?
g
Thanks! It shows up if I paste that code into a gist. I'll get you the exact message in one second
I get
Not enough information to infer type variable P
This is in code or a scratch file created from within an Android project in Android Studio if that matters
It works in the playground though 🤔
m
Yeah, note that there was a problem in the new inference in 1.3.72 indeed but now this example works in 1.4
g
Interesting. When paring down the code from the original MvRx code to the minimal repro, I may be paired it down to the point where it hit this 1.3.72 bug. When I try to upgrade MvRx, to 1.4, I get
e: /home/gabriel/repos/MvRx/counter/src/main/java/com/airbnb/mvrx/counter/CounterFragment.kt: (25, 48): Type 'MavericksDelegateProvider<TypeVariable(T), TypeVariable(VM)>' has no method 'getValue(CounterFragment, KProperty<*>)' and thus it cannot serve as a delegate
Okay, I've simplified it down. how about this:
Copy code
import kotlin.properties.PropertyDelegateProvider
import kotlin.properties.ReadOnlyProperty

class TypeInference {
    val works by providerFun<TypeInference, String>()
    val doesntWork: String by providerFun()
}

inline fun <T, reified V> T.providerFun() = PropertyDelegateProvider { _: T, _ ->
    ReadOnlyProperty<T, V> { _, _ -> TODO("Not Implemented") }
}
T should be able to be inferred right?
I replied to the bug but here is one that works in 1.3.72 and passes in 1.4.0