Cannot use reified types from an extension of a final class
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 3.2k
- Forks
- 106
- Avg merge
- 6d 13h
- Merged PRs (30d)
- 1
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the example with a final Demo class and its extension, then compare it with the stated working case using a non-final class. Trace how @inline(__always) and the generic fetchSingle function are translated for the Kotlin compiler, and consider the issue resolved when the final-class extension compiles without the reported KClass type mismatch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, swift
- Domain
- compilers, mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100