Skip to content

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

@wfltaylor

Description

@wfltaylor

If a @JS struct doesn’t have an initialiser that accepts all of its fields in-order (with the names matching exactly), the generated code fails to compile. In other words, the struct must have an initialiser that matches the signature of the generated memberwise one.

For example, this struct generates code that fails to compile:

@JS public struct Animal {

    public var size: Size
    public var age: Age

    @JS public init(age: Age, size: Size) {
        self.age = age
        self.size = size
    }

}
extension Animal: _BridgedSwiftStruct {
    @_spi(BridgeJS) @_transparent public static func bridgeJSStackPop() -> Animal {
        let size = Size.bridgeJSStackPop()
        let age = Age.bridgeJSStackPop()
        return Animal(size: size, age: age) // error: argument 'age' must precede argument 'size'
    }

Possible solutions include diagnosing this more clearly, or maybe the @js macro could generate its own @_spi(BridgeJS) initialiser?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions