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
4 changes: 2 additions & 2 deletions Sources/JExtractSwiftLib/Swift2JavaVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift.org project authors
// Copyright (c) 2024-2025 Apple Inc. and the Swift.org project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
Expand Down Expand Up @@ -84,7 +84,7 @@ final class Swift2JavaVisitor {
}

func visit(extensionDecl node: ExtensionDeclSyntax, in parent: ImportedNominalType?) {
guard parent != nil else {
guard parent == nil else {
// 'extension' in a nominal type is invalid. Ignore
return
}
Expand Down
48 changes: 48 additions & 0 deletions Tests/JExtractSwiftTests/ExtensionImportTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift.org project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import JExtractSwiftLib
import Testing

final class ExtensionImportTests {
let interfaceFile =
"""
extension MyStruct {
public func methodInExtension() {}
}

public struct MyStruct {}
"""

@Test("Import extensions: Swift thunks")
func data_swiftThunk() throws {
try assertOutput(
input: interfaceFile, .ffm, .swift,
expectedChunks: [
"""
@_cdecl("swiftjava_getType_SwiftModule_MyStruct")
public func swiftjava_getType_SwiftModule_MyStruct() -> UnsafeMutableRawPointer /* Any.Type */ {
return unsafeBitCast(MyStruct.self, to: UnsafeMutableRawPointer.self)
}
""",
"""
@_cdecl("swiftjava_SwiftModule_MyStruct_methodInExtension")
public func swiftjava_SwiftModule_MyStruct_methodInExtension(_ self: UnsafeRawPointer) {
self.assumingMemoryBound(to: MyStruct.self).pointee.methodInExtension()
}
"""
]
)
}
}
Loading