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?
If a
@JSstruct 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:
Possible solutions include diagnosing this more clearly, or maybe the @js macro could generate its own
@_spi(BridgeJS)initialiser?