wrap-java: Fix escaped method calls and handle $ prefix#729
Merged
ktoso merged 4 commits intoswiftlang:mainfrom May 1, 2026
Merged
wrap-java: Fix escaped method calls and handle $ prefix#729ktoso merged 4 commits intoswiftlang:mainfrom
ktoso merged 4 commits intoswiftlang:mainfrom
Conversation
sidepelican
commented
May 1, 2026
| var escaped = false | ||
| var copy = self | ||
| if starts(with: "$") { | ||
| copy = "_\(self.dropFirst())" |
Contributor
Author
There was a problem hiding this comment.
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 |
Collaborator
There was a problem hiding this comment.
Sounds good, thanks for checking the ‘’
ktoso
approved these changes
May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes two issues related to Java-to-Swift method name mapping in wrap-java.
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.
This PR ensures the original name is passed to the macro arguments when a name is escaped.
$PrefixMethods 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.