Skip to content

Commit c43de37

Browse files
committed
[JExtract] Fix importing extensions
The condition was incorrect in `Swift2JavaVisitor.visit(extensionDecl:parent:)`. All valid extensions were simply ignored.
1 parent 1ac73e4 commit c43de37

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

Sources/JExtractSwiftLib/Swift2JavaVisitor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ final class Swift2JavaVisitor {
8484
}
8585

8686
func visit(extensionDecl node: ExtensionDeclSyntax, in parent: ImportedNominalType?) {
87-
guard parent != nil else {
87+
guard parent == nil else {
8888
// 'extension' in a nominal type is invalid. Ignore
8989
return
9090
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2024 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+
final class ExtensionImportTests {
19+
let interfaceFile =
20+
"""
21+
extension MyStruct {
22+
public func methodInExtension() {}
23+
}
24+
25+
public struct MyStruct {}
26+
"""
27+
28+
@Test("Import extensions: Swift thunks")
29+
func data_swiftThunk() throws {
30+
try assertOutput(
31+
input: interfaceFile, .ffm, .swift,
32+
expectedChunks: [
33+
"""
34+
@_cdecl("swiftjava_getType_SwiftModule_MyStruct")
35+
public func swiftjava_getType_SwiftModule_MyStruct() -> UnsafeMutableRawPointer /* Any.Type */ {
36+
return unsafeBitCast(MyStruct.self, to: UnsafeMutableRawPointer.self)
37+
}
38+
""",
39+
"""
40+
@_cdecl("swiftjava_SwiftModule_MyStruct_methodInExtension")
41+
public func swiftjava_SwiftModule_MyStruct_methodInExtension(_ self: UnsafeRawPointer) {
42+
self.assumingMemoryBound(to: MyStruct.self).pointee.methodInExtension()
43+
}
44+
"""
45+
]
46+
)
47+
}
48+
}

0 commit comments

Comments
 (0)