Nested inline functions with reified type parameters and type erasure

The type passed to jsonToObject is HttpResponse<T> where T is the type parameter of sendRequestAsync.

It seems like the type parameter T of sendRequestAsync is not replaced in the bytecode when it is never used directly in any way. Adding null is T above val brokenObject “fixes” the code

Here’s a simpler repro that appears to be the same issue:

private inline fun <reified T> topMethod() {
        innerMethod {
            accessClass<T>()
        }
    }

    private fun innerMethod(block: () -> Unit) {
        block()
    }

    private inline fun <reified Z> accessClass() { Z::class }

Calling topMethod() throws java.lang.UnsupportedOperationException: This function has a reified type parameter and thus can only be inlined at compilation time, not called directly.

1 Like