it seems like inline classes don't always get boxed when used as generics (contrary to what docs say). Is this a bug or expected behavior?
Copy code
inline class InlinePayload(val id: String)
fun <T> test(t: T): T {
return t
}
val (p1, p2) = listOf(test(3))
.zip(
listOf(test(InlinePayload("a"))), // (1)
::Pair)
.first()
println(p2.id) // (2) EXCEPTION!
It seems that
(1)
creates a
List<String>
rather than
List<InlinePayload>
and then
(2)
crashes with
Copy code
class java.lang.String cannot be cast to class ru.example.app.InlinePayload (java.lang.String is in module java.base of loader 'bootstrap'; ru.example.app.InlinePayload is in unnamed module of loader 'app')
dimsuz
06/28/2021, 11:14 AM
If I change
Copy code
::Pair
to
Copy code
{ p1, p2 -> p1 to InlinePayload(p2.id) }
i.e if I "rewrap" then no crash occurs
d
Dominaezzz
06/28/2021, 12:23 PM
Rip, this looks youtrack worthy.
d
dimsuz
06/28/2021, 12:24 PM
I thought so too, decided to ask just in case. Will report then!