Compilation error for class with sync/async function overloads: method is already defined

Offen
#906 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@Hokila arbeitet bereits daran.

Seit 03.9.2026.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
68/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
java, swift
Bereich
tooling

Rechercherichtung

Beginne mit JNISwift2JavaGenerator+JavaBindingsPrinting.swift bei printJavaBindingWrapperMethod und mit JavaTranslation.swift bei render, und reproduziere dann das gemeldete Beispiel für die sync/async-remove-Überladung. Verfolge, wie beide Swift-Methoden zu Java-Methoden werden, und stelle sicher, dass die generierte Klasse ohne den Fehler aufgrund der doppelten Methode kompiliert wird, während beide Bindings erhalten bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Commit hash: a736a64e18a85f55f267427a3c9de60ae8377b7a

Context:
While testing swiftly's support of existing Swift code, noticed that a code using a function that is overloaded with both sync and async variants is not compiling, failing with "method is already defined" error.

import Foundation

public class Test {
    public func remove(key: String) { /* sync */ }
    public func remove(key: String) async { }
}

Results in the following compilation error:

.../.build/plugins/outputs/lib/SwiftTestLib/destination/JExtractSwiftPlugin/src/generated/java/com/example/swiftexamplelib/Test.java:93: error: method removeKey(String) is already defined in class Test
    public java.util.concurrent.CompletableFuture<java.lang.Void> removeKey(java.lang.String key) {

Portion of the generated Java file:

  // ==== --------------------------------------------------
  // Test.remove
  
  /**
   * Downcall to Swift:
   * {@snippet lang=swift :
   * public func remove(key: String)
   * }
   */
  public void removeKey(java.lang.String key) {
    Test.$removeKey(key, this.$memoryAddress());
  } // printJavaBindingWrapperMethod(_:_:importedFunc:skipMethodBody:) @ JExtractSwiftLib/JNISwift2JavaGenerator+JavaBindingsPrinting.swift:950
  private static native void $removeKey(java.lang.String key, long selfPointer);
  
  
  // ==== --------------------------------------------------
  // Test.remove
  
  /**
   * Downcall to Swift:
   * {@snippet lang=swift :
   * public func remove(key: String) async
   * }
   */
  public java.util.concurrent.CompletableFuture<java.lang.Void> removeKey(java.lang.String key) {
    java.util.concurrent.CompletableFuture<java.lang.Void> future$ = new java.util.concurrent.CompletableFuture<java.lang.Void>();
    Test.$removeKey(key, this.$memoryAddress(), future$);
    return future$.thenApply((futureResult$) -> {
      return futureResult$;
    } // render(_:_:) @ JExtractSwiftLib/JNISwift2JavaGenerator+JavaTranslation.swift:2072
    );
  } // printJavaBindingWrapperMethod(_:_:importedFunc:skipMethodBody:) @ JExtractSwiftLib/JNISwift2JavaGenerator+JavaBindingsPrinting.swift:950
  private static native void $removeKey(java.lang.String key, long selfPointer, java.util.concurrent.CompletableFuture<java.lang.Void> result_future);

Environment: Swift 6.3.3 on macOS.

$ swiftly run swift --version
Apple Swift version 6.3.3 (swift-6.3.3-RELEASE)
Target: arm64-apple-macosx26.0

$ uname -a
Darwin it-C01241 25.6.0 Darwin Kernel Version 25.6.0: Fri Jul 31 19:18:49 PDT 2026; root:xnu-12377.161.14~5/RELEASE_ARM64_T6000 arm64
Vorherrschende Sprache
Swift
Sterne
1.3k
Forks
129
Ø Merge
7 Std. 16 Min.
Gemergte PRs (30 T.)
4

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus swiftlang/swift-java

Alle Issues in swiftlang/swift-java

Ähnliche Issues

Weitere Issues zu Swift

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.