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

オープン
#906 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Hokila がすでに取り組んでいます。

2026年9月3日 から。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
java, swift
領域
tooling

調査の方向性

JNISwift2JavaGenerator+JavaBindingsPrinting.swift の printJavaBindingWrapperMethod と JavaTranslation.swift の render から始め、報告された sync/async の remove オーバーロードの例を再現してください。2 つの Swift メソッドがどのように Java メソッドになるかを追跡し、両方のバインディングを保持したまま、生成されたクラスが重複メソッドエラーなしでコンパイルできることを確認してください。

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
Swift
スター
1.3k
フォーク
127
平均マージ
2日 14時間
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

swiftlang/swift-java のほかの issue

swiftlang/swift-java の issue をすべて見る

似ている issue

Swift の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。