Skip to content

jextract/jni: Fix duplicate protocol parameter wrappers for overloads - #962

Open
sidepelican wants to merge 2 commits into
swiftlang:mainfrom
sidepelican:duplicated_wrapper_name
Open

sidepelican wants to merge 2 commits into
swiftlang:mainfrom
sidepelican:duplicated_wrapper_name

Conversation

@sidepelican

Copy link
Copy Markdown
Contributor

Problem

When a protocol is used as a parameter, jextract generates a wrapper class in Swift. The name is based on the enclosing type, method name, and parameter name.

Overloads with the same protocol parameter can therefore generate duplicate wrapper classes:

// Original
public protocol Store {
  func value() -> Int64
}

public struct Client {
  public init(store: some Store) {}
  public init(store: some Store, extra: Int64) {}
}

// Generated
final class _Client_init_store_Wrapper: SwiftJavaStoreWrapper {
  ...
}

final class _Client_init_store_Wrapper: SwiftJavaStoreWrapper {
  ...
}
// ❌ Duplicate wrapper class

Solution

Generate the wrapper class name from the protocol types and reuse the class with the same protocol composition.

fileprivate final class _Java_Store_Box: SwiftJavaStoreWrapper {
  ...
}

The generated class is fileprivate and emitted once per Swift file, so different files can use the same wrapper name without conflicting.

This also adds support for protocol values within tuple parameters.

Fixes #946

@sidepelican
sidepelican requested a review from ktoso as a code owner November 11, 2026 03:01
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.

jextract/jni: Overloads with protocol parameters generate duplicate adapter classes

1 participant