You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BridgeJS] Compilation error when struct doesn’t have in-order initialiser #718
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:
@JSpublicstructAnimal{publicvarsize:Sizepublicvarage:Age@JSpublicinit(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?
Good catch! I think we need to require a synthesized init or a member-ordered explicit init to be available for structs. We can produce a clear diagnostic at codegen.
Activity
kateinoigakukun commentedon Apr 28, 2026
Good catch! I think we need to require a synthesized init or a member-ordered explicit init to be available for structs. We can produce a clear diagnostic at codegen.