Skip to content

JNI: keep Swift names that are Java keywords out of generated Java - #30

Open
piercifani wants to merge 2 commits into
jni/25-closure-method-namefrom
jni/26-java-identifiers
Open

piercifani wants to merge 2 commits into
jni/25-closure-method-namefrom
jni/26-java-identifiers

Conversation

@piercifani

Copy link
Copy Markdown

Stack 26/26 · base: jni/25-closure-method-name · previous: #29

Problem

Swift names that are Java keywords reached the generated Java as they are:

  • parameters long, short, double, int;
  • payload labels such as case split(long:short:);
  • properties written with backticks (static let `default`);
  • a wait() method, which redeclares Object.wait().

The Java didn't parse, which hid every other error javac would have reported. The Swift thunks broke the same way for class and default.

Changes

This ports upstream swiftlang#954:

  • Keyword names get a _ suffix in the Java bindings and the Swift thunks, when they are Java keywords or reserved Swift keywords: parameter names, closure parameter names and enum-case payload names. Argument labels are unchanged.
  • Getters and setters drop backticks: getDefault().
  • Methods that would redeclare a final java.lang.Object method (getClass, notify, notifyAll, wait) get a _ suffix. That includes the getter of a property named class.

In this stack, the same name is also used by the escaping-closure @JavaInterface (#2).

Kotlin in this PR

KeywordNamesTest.kt with Positions.swift:

position.label("long side", "short side")    // func label(long: String, short: String)
position.wait_()                             // func wait()
Position.getDefault()                        // static let `default`
val split = Exposure.split(5, 2).case as Exposure.Case.Split
split.long_                                  // case split(long: Int64, short: Int64)

Why Skip needs it

Positions in a trading app are long or short. In a production Skip Fuse app (9 Skip modules) run through this stack, these names stopped javac at parsing in 6 modules. Once javac can parse everything, it reports every real error, and the remaining compile errors are type errors in other generated code.

Testing

🤖 Generated with Claude Code

piercifani and others added 2 commits November 4, 2026 15:59
Ports swiftlang#954. Parameter, closure parameter and enum case
payload names that are Java or reserved Swift keywords, such as `long`,
`int` or `default`, get a `_` suffix in the Java bindings and the Swift
thunks; getter and setter names drop a property's backticks; and methods
that would redeclare a final `java.lang.Object` method (`getClass`, `notify`,
`notifyAll`, `wait`) get a `_` suffix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cla-bot cla-bot Bot added the cla-signed label Nov 4, 2026
@piercifani
piercifani added this pull request to stack #12 November 4, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant