swiftlang / swiftlang/swift-java

Classes with a type parameter fail to compile

Open
#533 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature:jextract
Dominant language
Swift
Stars
1.2k
Forks
123
Avg merge
1d 7h
Merged PRs (30d)
16

Description

I searched through the issues, but couldn't find an explicit issue about the missing support for generics. In particular if you have a public class such as:

public class Foo<T> {
    public init() {}
}

in Samples/SwiftJavaExtractFFMSampleApp/Sources/MySwiftLibrary/Foo.swift, then the Swift wrappers compilation currently fails with:

error: generic parameter 'T' could not be inferred
 26 | @_cdecl("swiftjava_getType_MySwiftLibrary_Foo")
 27 | public func swiftjava_getType_MySwiftLibrary_Foo() -> UnsafeMutableRawPointer /* Any.Type */ {
 28 |   return unsafeBitCast(Foo.self, to: UnsafeMutableRawPointer.self)
    |                        |- error: generic parameter 'T' could not be inferred
    |                        `- note: explicitly specify the generic arguments to fix this issue

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 with Samples/SwiftJavaExtractFFMSampleApp/Sources/MySwiftLibrary/Foo.swift and inspect the generated Swift wrapper at the reported swiftjava_getType_MySwiftLibrary_Foo function. Reproduce the compilation failure for Foo and trace how the generic type is represented in the wrapper. Done means the Swift wrappers compile for the generic public class without the generic-parameter inference error.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.