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
8 changes: 8 additions & 0 deletions Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,14 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor {
guard let effects = collectEffects(signature: node.signature) else {
return .skipChildren
}
if effects.isAsync || effects.isThrows {
diagnose(
node: node,
message: "@JS struct initializer cannot be async or throw",
hint: "BridgeJS calls this initializer to rebuild struct values passed from JavaScript"
)
return .skipChildren
}

let structAbiName = exportedStructByName[structKey]?.abiName ?? "unknown"
let constructor = ExportedConstructor(
Expand Down
15 changes: 15 additions & 0 deletions Plugins/BridgeJS/Tests/BridgeJSToolTests/DiagnosticsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,21 @@ import Testing
#expect(skeleton.exported != nil)
}

@Test
func throwingStructInitProducesDiagnostic() throws {
let source = """
@JS struct Point {
var x: Double

@JS init(x: Double) throws(JSException) {
self.x = x
}
}
"""
let diagnostics = try #require(moduleDiagnostics(source: source))
#expect(diagnostics.description.contains("@JS struct initializer cannot be async or throw"))
}

@Test
func structWithoutExplicitInitSucceeds() throws {
let source = """
Expand Down
Loading