swiftwasm / swiftwasm/JavaScriptKit

Mutating functions are not supported on structs

Open
#736 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
986
Forks
76
Avg merge
21h 11m
Merged PRs (30d)
4

Description

Marking a mutating function on a structure @JS results in a compilation failure in the generated code.

For example, this struct generates code which fails to compile.

@JS struct Counter {

    var number: Int

    @JS public mutating func increment() {
        number += 1
    }

}
@_expose(wasm, "bjs_Counter_increment")
@_cdecl("bjs_Counter_increment")
public func _bjs_Counter_increment() -> Void {
    #if arch(wasm32)
    Counter.bridgeJSLiftParameter().increment() // error: cannot use mutating member on immutable value: function call returns immutable value
    #else
    fatalError("Only available on WebAssembly")
    #endif
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the @JS struct handling and the generated _bjs_Counter_increment wrapper shown in the issue, then reproduce the compilation failure with the Counter example. Done means an @JS struct with a mutating function generates code that compiles successfully for WebAssembly.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, swift, wasm
Domain
compilers, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.