Skip to content
Open
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
102 changes: 65 additions & 37 deletions skipstone/Sources/SkipSyntax/Kotlin/KotlinBridgeToKotlinVisitor.swift

Large diffs are not rendered by default.

157 changes: 117 additions & 40 deletions skipstone/Sources/SkipSyntax/Kotlin/KotlinBridgeToSwiftVisitor.swift

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions skipstone/Sources/SkipSyntax/Kotlin/KotlinBridgeTransformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,17 @@ extension KotlinSyntaxNode {
}

extension TypeSignature {
/// Whether this function type matches the given one, ignoring `@MainActor`.
///
/// Codebase info adds the `@MainActor` flag to the members of main actor-isolated types, but a declared type only has it when the member is explicitly annotated. A requirement and its witness can also differ in isolation.
func isSameFunctionType(as declaredType: TypeSignature) -> Bool {
var apiFlags = self.apiFlags
apiFlags.options.remove(.mainActor)
var declaredAPIFlags = declaredType.apiFlags
declaredAPIFlags.options.remove(.mainActor)
return withAPIFlags(apiFlags) == declaredType.withAPIFlags(declaredAPIFlags)
}

func callbackClosureType(apiFlags: APIFlags, kotlin: Bool) -> TypeSignature {
let isThrows = apiFlags.throwsType != .none
let throwsParameterType: TypeSignature = kotlin ? .named("Throwable", []).asOptional(true) : .javaObjectPointer.asOptional(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2596,7 +2596,7 @@ final class KotlinInterfaceDeclaration: KotlinStatement {
return true
}
} else if let originalFunctionDeclaration = originalMembers[i] as? KotlinFunctionDeclaration, let functionDeclaration = member as? KotlinFunctionDeclaration {
if originalFunctionDeclaration.isStatic == functionDeclaration.isStatic && originalFunctionDeclaration.name == functionDeclaration.name && originalFunctionDeclaration.functionType == functionDeclaration.functionType {
if originalFunctionDeclaration.isStatic == functionDeclaration.isStatic && originalFunctionDeclaration.name == functionDeclaration.name && originalFunctionDeclaration.functionType.isSameFunctionType(as: functionDeclaration.functionType) {
member.ensureLeadingNewlines(originalMembers[i].leadingNewlines)
originalMembers[i] = member
return true
Expand Down
11 changes: 11 additions & 0 deletions skipstone/Tests/SkipSyntaxTests/BridgeSendabilityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ final class BridgeSendabilityTests: XCTestCase {
assertReturnIsolation(bridge, unsafe: true)
}

func testTranspiledMainActorResult() async throws {
// The generated projection of a main actor-isolated type is main actor-isolated, and so Sendable
let bridge = try await generateBridge(swift: """
#if !SKIP_BRIDGE
@MainActor public final class Component { public var value: Int = 0 }
public protocol API { func fetch() async throws -> Component }
#endif
""", native: false)
assertReturnIsolation(bridge, unsafe: false)
}

/// The index just past the `}` closing the first `{` at or after `index`.
private static func closingBraceIndex(after index: String.Index, in text: String) -> String.Index {
var depth = 0
Expand Down
Loading
Loading