Skip to content

jextract/jni: Expose Swift protocol requirement defaults to Java callbacks #948

Open

Description

@teamhimeh

Problem

JNI callback interfaces currently leave protocol requirements abstract even when Swift supplies an unconditional implementation in an extension. Java implementors must repeat that implementation instead of inheriting the Swift behavior.

Example

public protocol Greeter {
  func name() -> String
  func greeting() -> String
}

extension Greeter {
  public func greeting() -> String { "Hello, \(name())" }
}

With Java callbacks enabled, it would be useful for a Java implementation to provide only name() and inherit the Swift implementation of greeting():

Greeter greeter = () -> "World";
String message = greeter.greeting(); // "Hello, World"

The Swift body should remain the implementation, and its calls to other requirements should dispatch to the Java receiver, including any Java overrides.

This is related to #562, which discusses exposing extension members as Java default methods, and #891, which reports a compilation error when a protocol requirement has a default implementation.

Reference workaround implementation: qoncept#11

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions