Skip to content

jextract/ffm: Treat underscore labels as empty suffixes in function overloads#735

Merged
ktoso merged 1 commit intoswiftlang:mainfrom
sidepelican:underscore_label_overload
May 11, 2026
Merged

jextract/ffm: Treat underscore labels as empty suffixes in function overloads#735
ktoso merged 1 commit intoswiftlang:mainfrom
sidepelican:underscore_label_overload

Conversation

@sidepelican
Copy link
Copy Markdown
Contributor

Currently, when a function overload uses an underscore (_) as an argument label, the generator uses the underscore literally as a suffix for the Java method name.

func foo(a: Int)    // in Java, void fooA(long a)
func foo(_ b: Int)  // in Java, void foo_(long b)

In Swift, _ is not an identifier; it simply denotes the omission of a label. Therefore, IMO, using it as a literal suffix in Java feels unnatural.

This PR updates the naming logic for function overloads to treat the _ label as an empty suffix.

Notes

This change can lead to name collisions in specific cases. For example:

public func takeValue(_ a: Int, b: Int) -> Int { 0 }
public func takeValue(b: Int, _ c: Int) -> Int { 0 }

With this PR, both methods would map to takeValueB.
However, even if we kept the underscore (the previous behavior), collisions would still be unavoidable if a function like func takeValue_(b: Int) existed.
To approach such corner-case collisions, we should eventually provide a way for users to explicitly specify the export name. (like @JavaExport("export_name")).

@sidepelican sidepelican requested a review from ktoso as a code owner May 11, 2026 07:25
@ktoso
Copy link
Copy Markdown
Collaborator

ktoso commented May 11, 2026

This sounds good to me, long term solution as well, thank you!

Maybe worth a new issue about the longer term fix

@ktoso ktoso merged commit f6f682b into swiftlang:main May 11, 2026
64 checks passed
@sidepelican sidepelican deleted the underscore_label_overload branch May 11, 2026 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants