Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ public func globalOverloaded(b: Int) {
p("globalOverloaded(b: \(b))")
}

public func globalOverloaded(_ c: Int) {
p("globalOverloaded(c: \(c))")
}

// ==== Internal helpers

func p(_ msg: String, file: String = #fileID, line: UInt = #line, function: String = #function) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static void examples() {
var origBytes = arena.allocateFrom("foobar");
var origDat = Data.init(origBytes, origBytes.byteSize(), arena);
CallTraces.trace("origDat.count = " + origDat.getCount());

var retDat = MySwiftLibrary.globalReceiveReturnData(origDat, arena);
retDat.withUnsafeBytes((retBytes) -> {
var str = retBytes.getString(0);
Expand All @@ -104,6 +104,7 @@ static void examples() {
// Overloaded functions with label-based disambiguation
MySwiftLibrary.globalOverloadedA(100);
MySwiftLibrary.globalOverloadedB(200);
MySwiftLibrary.globalOverloaded(300);

System.out.println("DONE.");
}
Expand Down
11 changes: 6 additions & 5 deletions Sources/JExtractSwiftLib/JavaIdentifierFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ package struct JavaIdentifierFactory {
return ""
default:
guard needsSuffix(for: baseName) else { return "" }
let labels = decl.functionSignature.parameters
.compactMap { $0.argumentLabel }
// A parameterless function that still conflicts (e.g. with a property
// getter) gets a bare "_" so it compiles as a distinct Java method.
guard !labels.isEmpty else { return "_" }
if decl.functionSignature.parameters.isEmpty {
// A parameterless function that still conflicts (e.g. with a property
// getter) gets a bare "_" so it compiles as a distinct Java method.
return "_"
}
let labels = decl.functionSignature.parameters.compactMap(\.argumentLabel)
// Join labels in camelCase: takeValue(a:) → takeValueA
return labels.map { $0.prefix(1).uppercased() + $0.dropFirst() }.joined()
}
Expand Down
3 changes: 3 additions & 0 deletions Tests/JExtractSwiftTests/MethodImportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ final class MethodImportTests {

public func takeValue(a: Swift.String) -> Swift.Int
public func takeValue(b: Swift.String) -> Swift.Int
public func takeValue(_ c: Swift.String) -> Swift.Int
public func uniqueFunc(x: Swift.Int) -> Swift.Int
public func overloaded(a: Swift.Int) -> Swift.Int
public func overloaded(a: Swift.String) -> Swift.Int
Expand All @@ -551,6 +552,7 @@ final class MethodImportTests {
expectedChunks: [
"public static long takeValueA(java.lang.String a)",
"public static long takeValueB(java.lang.String b)",
"public static long takeValue(java.lang.String c)",
]
)
}
Expand Down Expand Up @@ -679,6 +681,7 @@ final class MethodImportTests {
expectedChunks: [
"public static long takeValueA(java.lang.String a)",
"public static long takeValueB(java.lang.String b)",
"public static long takeValue(java.lang.String c)",
]
)
}
Expand Down
Loading