Skip to content

BridgeJS: Diagnose struct initializer parameter order mismatch#733

Merged
krodak merged 1 commit intomainfrom
kr/struct-init-diagnostic
Apr 30, 2026
Merged

BridgeJS: Diagnose struct initializer parameter order mismatch#733
krodak merged 1 commit intomainfrom
kr/struct-init-diagnostic

Conversation

@krodak
Copy link
Copy Markdown
Member

@krodak krodak commented Apr 30, 2026

Overview

Fixes #718. Adds a diagnostic when a @JS struct's explicit @JS init has parameters in a different order than the struct's stored property declarations.

The stack ABI pushes/pops struct fields in declaration order, so bridgeJSStackPop() always reconstructs the struct using property declaration order. If the user writes an init with a different parameter order, the generated code fails to compile with a confusing Swift error. This change catches the mismatch at codegen time with a clear message.

Example diagnostic:

test.swift:5:5: error: @JS struct initializer parameters must match stored properties in declaration order. Expected (size, age), got (age, size)
  5 |     @JS init(age: Int, size: Double) {
    |     `- error: ...

What changed:

  • SwiftToSkeleton.visitPost(_: StructDeclSyntax) now validates that when an explicit @JS init exists, its parameter labels match the struct's property names in declaration order.
  • If no @JS init is declared, the synthesized memberwise init is assumed (always correct).
  • Three new tests: mismatched order produces diagnostic, matching order succeeds, no explicit init succeeds.

@krodak krodak force-pushed the kr/struct-init-diagnostic branch 2 times, most recently from 566d76b to a8c17d7 Compare April 30, 2026 10:49
@krodak krodak self-assigned this Apr 30, 2026
@krodak krodak force-pushed the kr/struct-init-diagnostic branch from a8c17d7 to e60402c Compare April 30, 2026 10:51
@krodak krodak requested a review from kateinoigakukun April 30, 2026 11:14
@krodak krodak force-pushed the kr/struct-init-diagnostic branch from e60402c to f90fe98 Compare April 30, 2026 20:12
@krodak krodak merged commit 824c051 into main Apr 30, 2026
13 checks passed
@krodak krodak deleted the kr/struct-init-diagnostic branch April 30, 2026 20:41
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.

[BridgeJS] Compilation error when struct doesn’t have in-order initialiser

2 participants