swiftlang / swiftlang/swift-java

[Java2Swift] Generating invalid code for methods with generic parameters

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

Nobody has claimed this yet.

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

Description

The code generation for java.net.ContentHandler produces invalid code due when a method signature references a generic type, like JavaClass.

// Auto-generated by Java-to-Swift wrapper generator.
import JavaKit
import JavaRuntime

@JavaClass("java.net.ContentHandler")
open class ContentHandler: JavaObject {
  @JavaMethod
  @_nonoverride public convenience init(environment: JNIEnvironment? = nil)

  @JavaMethod
  open func getContent(_ arg0: URLConnection?) throws -> JavaObject!

  @JavaMethod
  open func getContent(_ arg0: URLConnection?, _ arg1: [JavaClass?]) throws -> JavaObject!
}
/Users/coleman/Developer/Android/Sources/AndroidJavaNet/ContentHandler.swift:14:57: error: reference to generic type 'JavaClass' requires arguments in <...>
12 | 
13 |   @JavaMethod
14 |   open func getContent(_ arg0: URLConnection?, _ arg1: [JavaClass?]) throws -> JavaObject!
   |                                                         `- error: reference to generic type 'JavaClass' requires arguments in <...>
15 | }
16 | 

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 the Java2Swift generation for java.net.ContentHandler and reproduce the compiler error shown for AndroidJavaNet/ContentHandler.swift. Trace how the generic parameter in the getContent signature is emitted; done means the generated Swift uses a valid generic JavaClass type and compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, swift
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.