Skip to content

BridgeJS: Emit protocol array for-loop as a single CodeBlockItemSyntax#1

Closed
krodak wants to merge 1 commit intountitled-in-brackets:chore/relax-swift-syntax-constraintfrom
PassiveLogic:kr/fix-protocol-array-codegen-formatting
Closed

BridgeJS: Emit protocol array for-loop as a single CodeBlockItemSyntax#1
krodak wants to merge 1 commit intountitled-in-brackets:chore/relax-swift-syntax-constraintfrom
PassiveLogic:kr/fix-protocol-array-codegen-formatting

Conversation

@krodak
Copy link
Copy Markdown

@krodak krodak commented Apr 9, 2026

Overview

Fixes the formatter mis-rendering flagged by @kateinoigakukun in swiftwasm#714 so we can land the swift-syntax 603 bump on CI.

The protocol array lowering in StackCodegen.lowerProtocolArrayStatements built its for-loop from three separate CodeBlockItemSyntax fragments ("for ... {", body line, "}"). swift-syntax 603's formatter then rendered the closing brace glued to the previous line, producing output like:

for __bjs_elem_ret in ret {
_swift_js_push_i32((__bjs_elem_ret as! _BridgedSwiftProtocolExportable).bridgeJSLowerAsProtocolReturn())}

This change combines the for-loop into a single multi-line CodeBlockItemSyntax using a string-interpolated multi-line literal, matching the pattern already used for nullable protocol return lowering a bit further up in the file. The formatter now produces consistent output across swift-syntax 600/601/602/603:

for __bjs_elem_ret in ret {
    _swift_js_push_i32((__bjs_elem_ret as! _BridgedSwiftProtocolExportable).bridgeJSLowerAsProtocolReturn())
}

The only affected snapshot is Protocol.swift (two occurrences).

Verification

Ran the BridgeJS test suite against every swift-syntax version the CI matrix covers, all 105/106 tests passing:

  • `swift test --package-path ./Plugins/BridgeJS` (default 600.0.1)
  • `BRIDGEJS_OVERRIDE_SWIFT_SYNTAX_VERSION=601.0.0 swift test ...`
  • `BRIDGEJS_OVERRIDE_SWIFT_SYNTAX_VERSION=602.0.0 swift test ...`
  • `BRIDGEJS_OVERRIDE_SWIFT_SYNTAX_VERSION=603.0.0 swift test ...`

Merge this into `chore/relax-swift-syntax-constraint` and the PR's CI matrix should go green.

The protocol array lowering built its for-loop from separate
CodeBlockItemSyntax fragments ('for ... {', body, '}'), which is not
a well-formed statement unit. swift-syntax 603's formatter then
rendered the closing brace glued to the previous line in the
generated output.

Combine the for-loop into a single multi-line CodeBlockItemSyntax,
matching the pattern already used for nullable protocol return
lowering, so the formatter produces consistent output across
swift-syntax 600-603.
@krodak
Copy link
Copy Markdown
Author

krodak commented Apr 9, 2026

Superseded by swiftwasm#716, which covers this fix and more (all three StackCodegen for-loop helpers + the struct/enum consumer trivia-glue bug). The protocol-array lowering fix from this PR is already merged into swiftwasm/JavaScriptKit as part of swiftwasm#716.

@krodak krodak closed this Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant