Repository navigation
JNI: keep Swift names that are Java keywords out of generated Java - #30
Open
piercifani wants to merge 2 commits into
Open
piercifani wants to merge 2 commits into
piercifani wants to merge 2 commits into
Conversation
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>
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.
Stack 26/26 · base:
jni/25-closure-method-name· previous: #29Problem
Swift names that are Java keywords reached the generated Java as they are:
long,short,double,int;case split(long:short:);static let `default`);wait()method, which redeclaresObject.wait().The Java didn't parse, which hid every other error javac would have reported. The Swift thunks broke the same way for
classanddefault.Changes
This ports upstream swiftlang#954:
_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.getDefault().java.lang.Objectmethod (getClass,notify,notifyAll,wait) get a_suffix. That includes the getter of a property namedclass.In this stack, the same name is also used by the escaping-closure
@JavaInterface(#2).Kotlin in this PR
KeywordNamesTest.ktwithPositions.swift:Why Skip needs it
Positions in a trading app are
longorshort. 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
./gradlew :Samples:SwiftJavaExtractJNIKotlinSampleApp:testpasses (57 tests, includingKeywordNamesTest).JavaKeywordTests, andJNIJavaKitTestsexpectslong int_instead oflong int.swift testpasses.🤖 Generated with Claude Code