skiptools / skiptools/skip

Cannot use reified types from an extension of a final class

Open
#468 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug transpilation
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.