## Fix Swift overloads producing uncompilable Java wrappers #544
+28
−15
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.
Fixes #526
Problem
Swift allows method overloading using parameter labels (argument labels), where methods can have the same base name but different parameter labels:
In Swift, these are distinct methods because parameter labels are part of the function signature. However, when translated to Java, both were being generated with the same signature, causing compilation failures:
Error:
Solution
Modified the Java method name generation in
FFMSwift2JavaGenerator+JavaTranslation.swiftto append parameter labels as suffixes, creating unique method names that preserve Swift semantics while ensuring valid Java code.Implementation:
_a,_b)Example transformation:
Changes
Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+JavaTranslation.swift: Added logic to append parameter labels to method names for disambiguationSamples/SwiftJavaExtractFFMSampleApp/src/main/java/com/example/swift/HelloJava2Swift.java: Updated sample code to use new method naming convention (e.g.,globalTakeInt_i(),init_len_cap())Samples/SwiftJavaExtractFFMSampleApp/Sources/MySwiftLibrary/OverloadSample.swift: Added test cases with overloaded methods.