fix: generate mutable self binding for @JS mutating struct methods#743
Open
shivanshu877 wants to merge 4 commits intoswiftwasm:mainfrom
Open
fix: generate mutable self binding for @JS mutating struct methods#743shivanshu877 wants to merge 4 commits intoswiftwasm:mainfrom
shivanshu877 wants to merge 4 commits intoswiftwasm:mainfrom
Conversation
Adds `isMutating: Bool` to the `Effects` struct with backward-compatible Codable implementation. The field is only serialised when true, so existing JSON snapshots are unaffected. Old JSON without the key decodes cleanly via `decodeIfPresent(...) ?? false`. Part of the fix for swiftwasm#736.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #736
When a struct method declared with
@JSismutating, the macro-generated thunk currently emits a binding toselfthat the Swift compiler rejects because the call site needs a mutableselfto be reachable. The result is an "argument not mutable" / "cannot mutate" diagnostic at the macro-expansion site.The fix detects the
mutatingmodifier incollectEffects(the macro's effect-collection phase) and threads it through so the generated thunk bindsselfwith the right mutability. The change is local to the macro generator — runtime behaviour is unchanged for all non-mutating methods.Test plan
UPDATE_SNAPSHOTS=1set, or a maintainer can re-run the workflow once the new snapshot is committed.@JS struct Counter { mutating func increment() }reproduces Mutating functions are not supported on structs #736 before this change and compiles after.