Skip to content

Commit 680a3fc

Browse files
authored
Fix crash when Any type parsing (#528)
1 parent 614af0d commit 680a3fc

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

Sources/JExtractSwiftLib/SwiftTypes/SwiftType.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,10 @@ extension SwiftType {
365365
}
366366
typeDecl = lookupContext.symbolTable.lookupNestedType(name.text, parent: parentDecl)
367367
} else {
368-
typeDecl = try lookupContext.unqualifiedLookup(name: Identifier(name)!, from: name)
368+
guard let ident = Identifier(name) else {
369+
throw TypeTranslationError.unknown(originalType)
370+
}
371+
typeDecl = try lookupContext.unqualifiedLookup(name: ident, from: name)
369372
}
370373
guard let typeDecl else {
371374
throw TypeTranslationError.unknown(originalType)

Sources/SwiftJavaDocumentation/Documentation.docc/SupportedFeatures.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ SwiftJava's `swift-java jextract` tool automates generating Java bindings from S
6565
| Tuples: `(Int, String)`, `(A, B, C)` |||
6666
| Protocols: `protocol` |||
6767
| Protocols: `protocol` with associated types |||
68-
| Existential parameters `f(x: any SomeProtocol) ` |||
68+
| Existential parameters `f(x: any SomeProtocol)` (excepts `Any`) |||
6969
| Existential parameters `f(x: any (A & B)) ` |||
70-
| Existential return types `f() -> any Collection ` |||
70+
| Existential return types `f() -> any Collection` |||
7171
| Foundation Data and DataProtocol: `f(x: any DataProtocol) -> Data` |||
7272
| Opaque parameters: `func take(worker: some Builder) -> some Builder` |||
7373
| Opaque return types: `func get() -> some Builder` |||

Tests/JExtractSwiftTests/MethodImportTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ final class MethodImportTests {
4141
)
4242
4343
public func globalReturnClass() -> MySwiftClass
44+
45+
public func globalReturnAny() -> Any
4446
4547
public func swapRawBufferPointer(buffer: UnsafeRawBufferPointer) -> UnsafeMutableRawBufferPointer
4648
@@ -456,4 +458,18 @@ final class MethodImportTests {
456458
"""
457459
)
458460
}
461+
462+
@Test("Import: public func globalReturnAny() -> Any")
463+
func func_globalReturnAny() throws {
464+
var config = Configuration()
465+
config.swiftModule = "__FakeModule"
466+
let st = Swift2JavaTranslator(config: config)
467+
st.log.logLevel = .error
468+
469+
try st.analyze(path: "Fake.swift", text: class_interfaceFile)
470+
471+
#expect(!st.importedGlobalFuncs.contains {
472+
$0.name == "globalReturnAny"
473+
}, "'Any' return type is not supported yet")
474+
}
459475
}

0 commit comments

Comments
 (0)