I've recently enabled the new inference algorithm ...
# compiler
r
I've recently enabled the new inference algorithm with the Kotlin 1.4 nightly (1.4.0-dev-6071) compiler. I have an inline function that calls some Java code with signature:
Copy code
public <T> T deserialize(..., final Type type)
like this:
Copy code
inline fun <reified T: Set<Any?>> deser(...): T? = deserialize(..., object : TypeToken<T>() {}.type)
and this used to work fine with 1.4-M1 / old inference. However, now I get a runtime error when the java code attempts to return its value to the Kotlin code:
Copy code
Caused by: java.lang.ClassCastException: class java.util.LinkedHashSet cannot be cast to class java.lang.Void (java.util.LinkedHashSet and java.lang.Void are in module java.base of loader 'bootstrap')
I can "solve" this by explicitly adding the
T
type to the deserialize call i.e.
deserialize<T>(...)
, but I'm wondering if this is a bug with the new type inference? The compiler does not report any errors if the
<T>
is left off.
m
Thanks! At first glance, it seems like a bug to me, is there any chance we can get your project for testing?
r
@mikhail.zarechenskiy Upon further investigation I see that it appears to be this issue here: https://youtrack.jetbrains.com/issue/KT-25345. Not sure why this wasn't happening on 1.3.x or 1.4-M1 though because this issue is marked as affecting 1.2.41.
I've added a simple reproducer to that issue.
Maybe not, see my next post in #compiler ...
m
Speaking about https://youtrack.jetbrains.com/issue/KT-38427 it's intended behavior, more details in https://youtrack.jetbrains.com/issue/KT-36776 But we're going to reconsider it as found several problematic examples
👍 1
r
Ah, thanks for that background information.