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 @@ -675,7 +675,7 @@ extension FFMSwift2JavaGenerator {
throw JavaTranslationError.unhandledType(swiftType)
}

let javaType: JavaType = .class(package: nil, name: swiftNominalType.nominalTypeDecl.name)
let javaType: JavaType = .class(package: nil, name: swiftNominalType.nominalTypeDecl.qualifiedName)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a secondary bug found incidentally🤣

return TranslatedResult(
javaResultType: javaType,
annotations: resultAnnotations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ extension JNISwift2JavaGenerator {
}

// We assume this is a JExtract class.
let javaType = JavaType.class(package: nil, name: nominalType.nominalTypeDecl.name)
let javaType = JavaType.class(package: nil, name: nominalType.nominalTypeDecl.qualifiedName)
return TranslatedResult(
javaType: javaType,
annotations: resultAnnotations,
Expand Down
7 changes: 7 additions & 0 deletions Sources/JExtractSwiftLib/SwiftTypes/SwiftSymbolTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ package class SwiftSymbolTable {
self.parsedModule = parsedModule
self.importedModules = importedModules
}

func isModuleName(_ name: String) -> Bool {
if name == moduleName {
return true
}
return importedModules.keys.contains(name)
}
}

extension SwiftSymbolTable {
Expand Down
4 changes: 3 additions & 1 deletion Sources/JExtractSwiftLib/SwiftTypes/SwiftType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ extension SwiftType {
// FIXME: Need a more reasonable notion of which names are module names
// for this to work. What can we query for this information?
let parentType: SwiftType?
if memberType.baseType.trimmedDescription == "Swift" {
if let base = memberType.baseType.as(IdentifierTypeSyntax.self),
lookupContext.symbolTable.isModuleName(base.name.trimmedDescription)
{
parentType = nil
} else {
parentType = try SwiftType(memberType.baseType, lookupContext: lookupContext)
Expand Down
42 changes: 42 additions & 0 deletions Tests/JExtractSwiftTests/SwiftSymbolTableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//

@_spi(Testing) import JExtractSwiftLib
import SwiftJavaConfigurationShared
import SwiftParser
import SwiftSyntax
import Testing
Expand Down Expand Up @@ -49,4 +50,45 @@ struct SwiftSymbolTableSuite {
#expect(symbolTable.lookupType("Y", parent: nil) == nil)
#expect(symbolTable.lookupType("Z", parent: nil) == nil)
}

@Test(arguments: [JExtractGenerationMode.jni, .ffm])
func resolveSelfModuleName(mode: JExtractGenerationMode) throws {
try assertOutput(
input: """
import Foundation
public struct MyValue {}

public func fullyQualifiedType() -> MyModule.MyValue
public func fullyQualifiedType2() -> Foundation.Data
""",
mode,
.java,
swiftModuleName: "MyModule",
detectChunkByInitialLines: 1,
expectedChunks: [
"public static MyValue fullyQualifiedType(",
"public static Data fullyQualifiedType2(",
]
)
}

@Test(arguments: [JExtractGenerationMode.jni, .ffm])
func resolveSelfModuleName_moduleDuplicatedName(mode: JExtractGenerationMode) throws {
try assertOutput(
input: """
public struct MyModule {
public struct MyValue {}
}

public func fullyQualifiedType() -> MyModule.MyModule.MyValue
""",
mode,
.java,
swiftModuleName: "MyModule",
detectChunkByInitialLines: 1,
expectedChunks: [
"public static MyModule.MyValue fullyQualifiedType("
]
)
}
}
Loading