Skip to content

Mutating functions are not supported on structs #736

@wfltaylor

Description

@wfltaylor

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions