Skip to content

wrap-java: Handle generic parameter replacement in inherited methods#623

Merged
ktoso merged 4 commits intoswiftlang:mainfrom
sidepelican:operator
Mar 16, 2026
Merged

wrap-java: Handle generic parameter replacement in inherited methods#623
ktoso merged 4 commits intoswiftlang:mainfrom
sidepelican:operator

Conversation

@sidepelican
Copy link
Contributor

This PR is part of the improvements for #599.

Currently, generating code for JavaUnaryOperator results a compilation error.

.../JavaUnaryOperator.swift:14:36: error: cannot find type 'R' in scope
12 |   /// ```
13 |   @JavaMethod(typeErasedResult: "R!")
14 |   public func apply(_ arg0: T?) -> R!
   |                                    `- error: cannot find type 'R' in scope
15 | 
16 |   /// Java method `compose`.

In Java, Function<T, R> has two type parameters, but UnaryOperator<T> extends it by mapping both to a single type T.
wrap-java does not have a mechanism to substitute these generic parameters during inheritance, it incorrectly use R.

I have introduced a SubstitutionMap to track and apply generic parameter replacements during type resolution.

@sidepelican sidepelican requested a review from ktoso as a code owner March 16, 2026 09:03
Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work :)

@ktoso ktoso merged commit 77ebc55 into swiftlang:main Mar 16, 2026
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants