jextract/jni: Inherited protocol requirements can be renamed inconsistently when a child adds an overload

Đang mở
#941 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
58/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, swift

Hướng nghiên cứu

Start by reading the jextract/jni code that generates Java interfaces, box methods, and JNI thunks for protocol requirements; the issue does not name specific files or tests. Trace how the parent and child overloads in the NamingParent/NamingChild example get their Java names, then check whether both operations dispatch to the correct Swift requirement and the child box implements the parent interface. Done means Java compilation succeeds and both overloads call the intended Swift method.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Problem

When a child protocol adds an overload of an inherited requirement, the generated Java box can rename the inherited method based on the child's overload set. The parent Java interface still declares the method under its original name, so the child box does not implement the parent interface and Java compilation fails.

Example

public protocol NamingParent {
  var id: Int64 { get }
  func value(number: Int64) -> Int64
}

public protocol NamingChild: NamingParent {
  var tag: Int64 { get }
  func value(text: Int64) -> Int64
}

struct NamingValue: NamingChild {
  var id: Int64 { 1 }
  var tag: Int64 { 2 }

  func value(number: Int64) -> Int64 { number + 10 }
  func value(text: Int64) -> Int64 { text + 20 }
}

public func makeNamingChild() -> any NamingChild {
  NamingValue()
}

Swift argument labels distinguish the two requirements, but Java cannot represent both as value(long) on the child interface.

The parent interface exposes value(number:) as value(long). However, the generated child box can emit valueNumber(long) for that inherited requirement after considering the child's overload. This does not implement the parent's value(long) method.

The inherited requirement should keep the name declared by the parent interface. For example, the generated bindings could use value(long) for value(number:) and valueText(long) for value(text:). The Java interfaces, box methods, and JNI thunks should use consistent names so that both operations dispatch to the correct Swift requirement.

Reference workaround implementation: https://github.com/qoncept/swift-java/pull/3

Ngôn ngữ chính
Swift
Star
1.3k
Fork
127
Merge trung bình
1 giờ 6 phút
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của swiftlang/swift-java

Tất cả issue của swiftlang/swift-java

Issue tương tự

Thêm issue về Swift

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.