Compilation error for class with sync/async function overloads: method is already defined
维护者通常 1 天内回复
@Hokila 已经在做这个了。
开始于 2026年9月3日。
评估
调研方向
从 JNISwift2JavaGenerator+JavaBindingsPrinting.swift 中的 printJavaBindingWrapperMethod 和 JavaTranslation.swift 中的 render 开始,然后重现报告的 sync/async remove 重载示例。跟踪两个 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
- 平均合并
- 1 小时 6 分钟
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
swiftlang/swift-java 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
swiftlang/swift-java#955 ·
维护者通常 1 天内回复
-
wrap-java: Optional convenience methods can fail to compile when a parameter shadows the method name未关闭
难度 2/5 1-3 小时 新手友好度 70/100
swiftlang/swift-java#945 ·
维护者通常 1 天内回复
-
android
难度 2/5 1-3 小时 新手友好度 75/100
swiftlang/swift-java#663 · 4 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 56/100
swiftlang/swift-java#949 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
swiftlang/swift-java#948 ·
维护者通常 1 天内回复
查看 swiftlang/swift-java 的全部 Issue
相似的 Issue
-
feat: 앱 정보에 개인정보처리방침과 고객지원 연결可能已有人在做 @xrpjwk8 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 62/100
DeveloperAcademy-POSTECH/2026-C6-A13-Hear-I-am#120 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
jaywcjlove/quick-rss#448 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
VictorKildahl/cra#205 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
apple/container#2474 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
AttilaTheFun/visor#244 ·
维护者通常 1 天内回复