Skip to content

jextract/jni: Fix protocol parameter helper naming - #960

Merged
ktoso merged 3 commits into
swiftlang:mainfrom
sidepelican:existential_setter
Nov 10, 2026
Merged

ktoso merged 3 commits into
swiftlang:mainfrom
sidepelican:existential_setter

Conversation

@sidepelican

Copy link
Copy Markdown
Contributor

Problem

When a protocol is used as a parameter, jextract generates a wrapper class in Swift. The wrapper class name is based on the original Swift function signature, but the code that uses the wrapper refers to it by a name based on the Java method name.

This causes a naming mismatch in cases such as the following:

// Original
public protocol Animal {
  public func bark()
}

public struct Owner {
  public var animal: any Animal
}

// Generated

// Protocol parameter wrapper
final class _Owner_animal_newValue_Wrapper: SwiftJavaAnimalWrapper {
  ...
}

// Setter implementation
public func Java_com_example_swift_Owner__00024setAnimal__Ljava_lang_Object_2J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, newValue: jobject?, selfPointer: jlong) {
  ...
  newValueswiftObject$ = _Owner_setAnimal_newValue_Wrapper(_javaAnimalInterface: JavaAnimal(javaThis: newValue!, environment: environment))
  // ❌ Inconsistent wrapper name
  ...
}

Solution

Use the Java-translated function signature when generating the wrapper class name, so that the declaration and its references use the same name.

Fixes #949

@ktoso
ktoso merged commit 793e154 into swiftlang:main Nov 10, 2026
42 checks passed
@ktoso

ktoso commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Thanks! Sorry for slow reviews, I'm on holiday this week

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: Protocol property setters reference an incorrectly named adapter

2 participants