Skip to content

wrap-java: Fix escaped method calls and handle $ prefix#729

Merged
ktoso merged 4 commits intoswiftlang:mainfrom
sidepelican:doller_prefix_javamethod
May 1, 2026
Merged

wrap-java: Fix escaped method calls and handle $ prefix#729
ktoso merged 4 commits intoswiftlang:mainfrom
sidepelican:doller_prefix_javamethod

Conversation

@sidepelican
Copy link
Copy Markdown
Contributor

This PR fixes two issues related to Java-to-Swift method name mapping in wrap-java.

  1. Fix for Escaped Method Calls

Currently, Java methods that are Swift keywords (e.g., init) are correctly escaped in the Swift interface.
However, the macro was using these escaped names to call the Java methods, leading to failures.

expanded macro

This PR ensures the original name is passed to the macro arguments when a name is escaped.

  1. Handling of $ Prefix

Methods with a $ prefix were previously ignored.
To support future use cases like SwiftInstance.$memoryAddress(), I have enabled importing these methods by mapping the $ prefix to an underscore.

@sidepelican sidepelican requested a review from ktoso as a code owner May 1, 2026 04:06
var escaped = false
var copy = self
if starts(with: "$") {
copy = "_\(self.dropFirst())"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swift does not allow $ even when wrapped in backticks.
Therefore, always perform replacing.

 echo 'func `$foo`() {}' | swiftc -
<stdin>:1:6: error: cannot declare entity named '$foo'; the '$' prefix is reserved for implicitly-synthesized declarations
1 | func `$foo`() {}
  |      `- error: cannot declare entity named '$foo'; the '$' prefix is reserved for implicitly-synthesized declarations
2 | 

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, thanks for checking the ‘’

Copy link
Copy Markdown
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm yeah that’s reasonable I guess… otherwise we could do some _dollar$ or something like that but I don’t love those…

@ktoso ktoso merged commit bc57b8c into swiftlang:main May 1, 2026
64 checks passed
@sidepelican sidepelican deleted the doller_prefix_javamethod branch May 1, 2026 14:39
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