Skip to content

Commit 85346b5

Browse files
Fix FFM failing tests
1 parent 283b4ca commit 85346b5

3 files changed

Lines changed: 111 additions & 4 deletions

File tree

‎Sources/JExtractSwiftLib/FFM/CDeclLowering/FFMSwift2JavaGenerator+FunctionLowering.swift‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,8 +1020,16 @@ extension LoweredFunctionSignature {
10201020
if let selfExpr {
10211021
switch apiKind {
10221022
// Don't bother to create explicit ${Self}.init expression.
1023-
case .initializer, .subscriptGetter, .subscriptSetter: selfExpr
1024-
default: ExprSyntax(MemberAccessExprSyntax(base: selfExpr, name: .identifier(swiftAPIName)))
1023+
case .initializer, .subscriptGetter, .subscriptSetter:
1024+
selfExpr
1025+
case .prefixOperator:
1026+
ExprSyntax(DeclReferenceExprSyntax(baseName: .prefixOperator(swiftAPIName)))
1027+
case .binaryOperator:
1028+
ExprSyntax(DeclReferenceExprSyntax(baseName: .binaryOperator(swiftAPIName)))
1029+
case .postfixOperator:
1030+
ExprSyntax(DeclReferenceExprSyntax(baseName: .postfixOperator(swiftAPIName)))
1031+
default:
1032+
ExprSyntax(MemberAccessExprSyntax(base: selfExpr, name: .identifier(swiftAPIName)))
10251033
}
10261034
} else {
10271035
ExprSyntax(DeclReferenceExprSyntax(baseName: .identifier(swiftAPIName)))

‎Sources/JExtractSwiftLib/ThunkNameRegistry.swift‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,20 @@ package struct ThunkNameRegistry {
4545
.joined()
4646
}
4747

48+
let baseName =
49+
switch decl.apiKind {
50+
case .binaryOperator, .prefixOperator, .postfixOperator:
51+
JavaIdentifierFactory().makeJavaMethodName(decl)
52+
default:
53+
decl.name
54+
}
55+
4856
let name: String
4957
if let parent = decl.parentType, let nominalDecl = parent.asNominalTypeDeclaration {
5058
let parentName = nominalDecl.flatName
51-
name = "swiftjava_\(decl.module)_\(parentName)_\(decl.name)\(suffix)"
59+
name = "swiftjava_\(decl.module)_\(parentName)_\(baseName)\(suffix)"
5260
} else {
53-
name = "swiftjava_\(decl.module)_\(decl.name)\(suffix)"
61+
name = "swiftjava_\(decl.module)_\(baseName)\(suffix)"
5462
}
5563

5664
let emittedCount = self.duplicateNames[name, default: 0]
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2026 Apple Inc. and the Swift.org project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of Swift.org project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import JExtractSwiftLib
16+
import Testing
17+
18+
@Suite
19+
struct FFMOperatorsTests {
20+
private let source =
21+
"""
22+
infix operator ==+
23+
24+
public struct Number {
25+
public static func == (lhs: Number, rhs: Number) -> Bool {
26+
true
27+
}
28+
29+
public static func ==+ (lhs: Number, rhs: Number) -> Bool {
30+
true
31+
}
32+
}
33+
"""
34+
35+
@Test
36+
func equality_swiftThunk() throws {
37+
try assertOutput(
38+
input: source,
39+
.ffm,
40+
.swift,
41+
expectedChunks: [
42+
"""
43+
@_cdecl("swiftjava_SwiftModule_Number_isEqual_lhs_rhs")
44+
public func swiftjava_SwiftModule_Number_isEqual_lhs_rhs(_ lhs: UnsafeRawPointer, _ rhs: UnsafeRawPointer) -> Bool {
45+
return (lhs.assumingMemoryBound(to: Number.self).pointee == rhs.assumingMemoryBound(to: Number.self).pointee)
46+
}
47+
"""
48+
]
49+
)
50+
}
51+
52+
@Test
53+
func compoundOperator_swiftThunk() throws {
54+
try assertOutput(
55+
input: source,
56+
.ffm,
57+
.swift,
58+
expectedChunks: [
59+
"""
60+
@_cdecl("swiftjava_SwiftModule_Number_isEqualPlus_lhs_rhs")
61+
public func swiftjava_SwiftModule_Number_isEqualPlus_lhs_rhs(_ lhs: UnsafeRawPointer, _ rhs: UnsafeRawPointer) -> Bool {
62+
return (lhs.assumingMemoryBound(to: Number.self).pointee ==+ rhs.assumingMemoryBound(to: Number.self).pointee)
63+
}
64+
"""
65+
]
66+
)
67+
}
68+
69+
@Test
70+
func operator_javaBinding() throws {
71+
try assertOutput(
72+
input: source,
73+
.ffm,
74+
.java,
75+
expectedChunks: [
76+
"""
77+
private static class swiftjava_SwiftModule_Number_isEqual_lhs_rhs {
78+
""",
79+
"""
80+
private static class swiftjava_SwiftModule_Number_isEqualPlus_lhs_rhs {
81+
""",
82+
"""
83+
public static boolean isEqual(Number lhs, Number rhs) {
84+
""",
85+
"""
86+
public static boolean isEqualPlus(Number lhs, Number rhs) {
87+
""",
88+
]
89+
)
90+
}
91+
}

0 commit comments

Comments
 (0)