Skip to content

BridgeJS: Diagnose unsupported protocol conformers before lowering - #812

Merged
krodak merged 1 commit into
swiftwasm:mainfrom
PassiveLogic:fix/protocol-conformance-audit
Sep 7, 2026
Merged

BridgeJS: Diagnose unsupported protocol conformers before lowering#812
krodak merged 1 commit into
swiftwasm:mainfrom
PassiveLogic:fix/protocol-conformance-audit

Conversation

@krodak

@krodak krodak commented Sep 7, 2026

Copy link
Copy Markdown
Member

Overview

Currently, a Swift type can conform to a @JS protocol and compile successfully, then trap when returned to JavaScript because it does not conform to _BridgedSwiftProtocolExportable:

@JS protocol P { func ok() -> Int }
struct MyImpl: P { func ok() -> Int { 42 } }   // compiles fine
@JS func get() -> P { MyImpl() }               // compiles fine, then traps at runtime

This PR addresses that:

1. Diagnose unsupported conformers

Use the existing type index to check conformances after the exported API is collected. Diagnose unsupported conformers when their protocol crosses from Swift to JavaScript, while preserving lift-only and unused-protocol cases. Check closure directions, property accessors, and extension-declared conformances, including exported classes from dependencies.

2. Explain failures outside the generator's scope

Replace forced casts in generated glue with _bridgeJSUnwrapProtocolExportable. When a conformance cannot be checked during generation, the runtime failure names the concrete type, protocol, and supported alternatives instead of producing an opaque cast trap.

Test Plan

  • ./Utilities/format.swift
  • BridgeJS diagnostics and snapshots with SwiftSyntax 600, 601, 602, and 603.
  • ./Utilities/bridge-js-generate.sh
  • npm run check:bridgejs-dts
  • make unittest SWIFT_SDK_ID=swift-6.3-RELEASE_wasm BUILD_SYSTEM=native

@krodak krodak self-assigned this Sep 7, 2026
@krodak
krodak merged commit 62382f7 into swiftwasm:main Sep 7, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants