Skip to content

BridgeJS: Support case enums as imported function parameters and returns#756

Merged
krodak merged 1 commit into
swiftwasm:mainfrom
PassiveLogic:kr/case-enum-import
Jun 8, 2026
Merged

BridgeJS: Support case enums as imported function parameters and returns#756
krodak merged 1 commit into
swiftwasm:mainfrom
PassiveLogic:kr/case-enum-import

Conversation

@krodak

@krodak krodak commented Jun 8, 2026

Copy link
Copy Markdown
Member

Overview

Case enums (Swift enums without raw values or associated values) could not be used as parameters or return values of imported (@JSFunction) signatures. They already bridge across the export boundary as their Int32 tag, but the import path rejected them:

@JS enum Signal { case start; case stop }

@JSFunction func send(_ signal: Signal) throws(JSException)      // "Enum types are not yet supported in TypeScript imports"
@JSFunction func current() throws(JSException) -> Signal         // same error

The JavaScript glue already round-trips the Int32 tag in both directions; only the import-side type lowering and lifting in the code generator threw instead of producing the tag transfer.

This change enables case enums as imported parameters and return values by lowering and lifting their Int32 tag in the import context, identical to how the export side already handles them. The bridged representation is the case index, with the JS side exposing the value table and a numeric tag type in the generated .d.ts.

Adds an end-to-end runtime round-trip test and a codegen snapshot covering the new import shape.

@krodak krodak requested a review from kateinoigakukun June 8, 2026 14:26
@krodak krodak self-assigned this Jun 8, 2026
Case enums (enums without raw values or associated values) already bridged
across the export boundary as their Int32 tag, but the TypeScript import path
rejected them with "Enum types are not yet supported in TypeScript imports".
The JS glue already round-trips the tag in both directions, so enable case
enums as imported (@JSFunction) parameters and return values by lowering and
lifting that Int32 tag in the import context, matching the export side.

Adds a CaseEnumImports round-trip test and an EnumCaseImport codegen snapshot.
@krodak krodak force-pushed the kr/case-enum-import branch from 44d4c22 to 7d3faa0 Compare June 8, 2026 14:31
@krodak krodak merged commit c40fc49 into swiftwasm:main Jun 8, 2026
13 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