skip icon indicating copy to clipboard operation
skip copied to clipboard

Cannot use reified types from an extension of a final class

Open marcprux opened this issue 5 months ago • 0 comments

Using the @inline(__always) modified to cause a function to use reified types does not work when it is declared in an extension of a final class. It does work in an extension of a non-final class.

public final class Demo {
}

extension Demo {
    @inline(__always) public func fetchSingle<T: Decodable>(_ type: T.Type, data: Data) throws -> T {
        try JSONDecoder().decode(T.self, from: data)
    }
}

This raises the following Kotlin compiler error:

Argument type mismatch: actual type is 'KClass<ERROR CLASS: Type parameter T in qualified access>', but 'KClass<T (of fun <T : Decodable> fetchSingle)>' was expected.

marcprux avatar Jul 21 '25 05:07 marcprux