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

Aperta
#941 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
java, swift

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Swift
Stelle
1.3k
Fork
127
Merge medio
2g 14h
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di swiftlang/swift-java

Tutte le issue di swiftlang/swift-java

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.